VBS文件夾比較刪除同名同路徑文件

'遍歷一個文件夾下的所有文件夾
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 "刪除重復(fù)文件 " & 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
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。