有關背景/背景信息,請參閱this skeleton for recursive file access。鑑於這種文件夾結構:
tree /A ..\test
Folder PATH listing for volume eh
Volume serial number is 0ED6-233C
E:\TRIALS\SOTRIALS\ANSWERS\13415663\TEST
+---vbs
\---df
+---1
| +---b
| | \---x
| \---a
| \---abc
\---2
\---abc
\---xx
,並證明了這一點的概念代碼:
Option Explicit
Dim goFS : Set goFS = CreateObject("Scripting.FileSystemObject")
WScript.Quit Main()
Function Main()
Dim sDir : sDir = "..\test"
Dim oWorker : Set oWorker = New cWorker
Main = traverseDir(goFS.GetFolder(sDir), oWorker)
End Function
Class cWorker
Public Sub processFile(oFile)
' not needed
End Sub
Public Function processFolder(oFolder)
WScript.Echo "looking at", oFolder.Path
processFolder = True
If "abc" = oFolder.Name Then
WScript.Echo "will delete", oFolder.Path
oFolder.Delete
processFolder = False
End If
End Function
End Class
Function traverseDir(oDir, oWorker)
traverseDir = 0
Dim oF
For Each oF In oDir.Files
oWorker.processFile oF
Next
For Each oF In oDir.SubFolders
If oWorker.processFolder(oF) Then
traverseDir = traverseDir(oF, oWorker)
End If
Next
End Function
輸出:
cscript step02.vbs
looking at E:\trials\SoTrials\answers\13415663\test\vbs
looking at E:\trials\SoTrials\answers\13415663\test\df
looking at E:\trials\SoTrials\answers\13415663\test\df\1
looking at E:\trials\SoTrials\answers\13415663\test\df\1\b
looking at E:\trials\SoTrials\answers\13415663\test\df\1\b\x
looking at E:\trials\SoTrials\answers\13415663\test\df\1\a
looking at E:\trials\SoTrials\answers\13415663\test\df\1\a\abc
will delete E:\trials\SoTrials\answers\13415663\test\df\1\a\abc
looking at E:\trials\SoTrials\answers\13415663\test\df\2
looking at E:\trials\SoTrials\answers\13415663\test\df\2\abc
will delete E:\trials\SoTrials\answers\13415663\test\df\2\abc
證據:
tree /A ..\test
Folder PATH listing for volume eh
Volume serial number is 0ED6-233C
E:\TRIALS\SOTRIALS\ANSWERS\13415663\TEST
+---vbs
\---df
+---1
| +---b
| | \---x
| \---a
\---2
,你應該能夠編寫一個腳本,解決您的具體問題米
UPDATE:
看here看到應用到移動文件夾的方法。