Delete all files and folders but exclude a subfolder

前端 未结 11 1127
忘掉有多难
忘掉有多难 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:44

    Yes I know this is an old thread. I couldn't get any of the answers above to work in Powershell 5, so here is what I figured out:

    Get-ChildItem -Path $dir -Exclude 'name_to_ignore' |
    ForEach-Object {Remove-Item $_ -Recurse }
    

    This moves the -Recurse to Remove-Item instead of where the items are found.

提交回复
热议问题