删除排除的文件夹(大小写)

我发现一个VB脚本,使用FileSystemObject删除除了我指定的驱动器上的每个文件夹, 我的问题是,文件系统对象无法看到或尾随/领导 – 期间/空间枚举文件夹,但DIR命令可以

我试图运行一个命令来删除驱动器上的所有文件夹(这是从操作系统部署期间的winPE所以它是好的)除了我指定的一个,这是我工作的一部分工作正常,但不select特殊的命名文件夹有没有一种方法可以使用DIR命令来提供“Select Case”?

For each oFolder in oFSO.GetFolder(oEnvironment.Item("DestinationLogicalDrive") & "\").Subfolders Select Case lcase(oFolder.Name) Case "minint", "recycler", "system volume information", "deploy", "drivers", "_smstasksequence", "smstslog", "sysprep", "userstate" oLogging.CreateEntry "Skipping " & oFolder.Path, LogTypeInfo Case Else oLogging.CreateEntry "Deleting " & oFolder.Path, LogTypeInfo sCmd = "cmd /c rd ""\\?\" & oFolder.Path & """ /S /Q" iRc = RunAndLog(sCmd, false) TestAndLog iRc,"Execution: " & sCmd If iRC <> 0 Then If oFSO.FolderExists(oFolder.Path) Then oLogging.CreateEntry "Failed to delete " & oFolder.Path & " will try to rename", LogTypeError sCmd = "cmd /c rename """ & oFolder.Path & """ """ & oFolder.Name & ".bad""" iRc = RunAndLog(sCmd, false) TestAndLog iRc,"Execution: " & sCmd If iRC <> 0 Then If oFSO.FolderExists(oFolder.Path) Then oLogging.CreateEntry "Failed to delete or rename " & oFolder.Path & " the image WILL fail with NTLDR", LogTypeError ' TODO: notify, sit and wait End If End If End If End If End Select 

好吧,而不是使用filesystemobject我决定在FOR循环中使用简单的DIR命令,

 @echo off for /f "tokens=*" %%i in ('dir /s /a:D /b \\?\C:\*.*^|"%~dp0"\findstr /I /V /G:"%~dp0\exclusion.txt"') do Call :Delete "%%i" :Delete echo found %1 rd /s /q %1 

这里发生了什么事情:

DIR在\?\ C:\下recursion列出所有目录,并输出一个裸列表pipe输出到findstr,它排除在该文本文件中find的名字,然后调用delete命令,文件exclusion.txt包含我想要排除的项目给你和“TheOutcaste”从这个线程:forums.techguy.org/…/833910-solved-help-r-loop.html