要使用排除项删除的PowerShell或批处理脚本


2

删除特定路径下的所有内容,提供排除列表的好方法是什么?

例如

C:\
    MyFolder
        MyApp
        MyConfig
        MyWorld
        MyEverything
        MyBankDetails

如何删除C:\MyFolder\*.*留下MyBankDetails的文件夹结构类似于:

C:\
    MyFolder
        MyBankDetails

Answers:


2

以下是使用Powershell执行此操作的方法:

get-childitem C:\Myfolder\ -exclude "MyBankDetails" -recurse | foreach ($_) {remove-item $_.fullname}

它会递归C:\Myfolder并删除文件夹之外的所有内容MyBankDetails。您可以根据需要添加排除项,包括文件夹和文件。例如:

... -exclude "MyBankDetails","AnOtherFolder","File.txt",*.someFileExtension ...
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.