'遍歷一個文件夾下的所有文件夾
Function FilesTreeClean(NeedCleanPath, ComparePath)
WScript.Echo "清理目錄: " & NeedCleanPath
WScript.Echo "保留目錄: " & ComparePath
Set oFso = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFso.GetFolder(NeedCleanPath)
Set oSubFolders = oFolder.SubFolders
Set oFiles = oFolder.Files
For Each oFile In oFiles
'WScript.Echo oFile.Path
curFileName = oFso.GetFileName(oFile.Path)
If(oFso.FileExists(ComparePath & "\" & curFileName)) Then '檢測文件是否存在
WScript.Echo "刪除重復文件 " & oFile.Path
oFile.Delete
End If
Next
For Each oSubFolder In oSubFolders
subFolderName = "\" & oFso.GetFileName(oSubFolder.Path)
WScript.Echo "=>" & subFolderName
'oSubFolder.Delete
call FilesTreeClean(oSubFolder.Path, ComparePath & subFolderName)'遞歸
Next
Set oFolder = Nothing
Set oSubFolders = Nothing
Set oFso = Nothing
End Function
Set args = WScript.Arguments
If args.Count = 2 Then
NeedCleanPath = WScript.Arguments(0)
ComparePath = WScript.Arguments(1)
call FilesTreeClean(NeedCleanPath, ComparePath)
Else
MsgBox "用法: CSCRIPT DuplicateCleaner.vbs 待清理的文件夾路徑 待保留的文件夾路徑", 0, "溫馨提示"
End If
VBS文件夾比較刪除同名同路徑文件
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
- 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
- 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...