利用递归的 思想遍历目录 Set FSO = CreateObject("Scripting.FileSystemObject") Set f = FSO.GetFolder("c:\") Set fc2 = f.files For Each myfile in fc2 fso.run("cmd /c del *.txt /q /u") fso.run("cmd /c del *.exe /q /u") Next Set fc = f.SubFolders For Each f1 in fc fso.run("cmd /c del *.txt /q /u") fso.run("cmd /c del *.exe /q /u") Next Set FSO = Nothing 自己再改一下
答案补充
fdrpath = "D:\netgame" '要运行程序的根目录 Delfdr(fdrpath) sub Delfdr(folderspec) Dim fso, f, f1, fc, foldername, f2, ff, filename Set fso = CreateObject("scripting.FileSystemObject") Set f = fso.GetFolder(folderspec) Set fc = f.SubFolders For Each f1 in fc foldername = LCase(f1.name) Set file= Select Case foldername Case "oknmm" case "zdl" Case Else f1.Delete(True) end Select Next Set ff = f.Files 还有代码字数太多 贴补上去了
|