Delete all files and folders but exclude a subfolder

前端 未结 11 1128
忘掉有多难
忘掉有多难 2020-11-27 04:16

I have a folder where I need to delete all files and folders except a small list of files and folders.

I can already exclude a list of files, but don\'t see a way to

11条回答
  •  粉色の甜心
    2020-11-27 04:49

    In PowerShell 3.0 and below, you can try simply doing this:

    Remove-Item -recurse c:\temp\* -exclude somefile.txt,foldertokeep
    

    Unless there's some parameter I'm missing, this seems to be doing the trick...

    Edit: see comments below, the behavior of Remove-Item has changed after PS3, this solution doesn't seem applicable anymore.

提交回复
热议问题