Set objFSO = CreateObject("Scripting.FileSystemObject") set wshshell=wscript.createobject("wscript.shell") objStartFolder = "\\10.136.74.8\公用區" Set objFolder = objFSO.GetFolder(objStartFolder) Set colFiles = objFolder.Files For Each objFile in colFiles ' wshshell.popup objFile.Name,1,"folder.vbs" '刪除 Thumbs.db 和 acdb.err if objFile.Name="Thumbs.db" or objFile.Name="acdb.err" then objFSO.DeleteFile objfolder.path & "\" & objFile.Name elseIf objFile.DateLastModified < Now - 7 Then '顯示完整的文件名 ' wshshell.popup objfolder.path & "\" & objFile.Name,1,"folder.vbs" '刪除7天前的文件 ' objFSO.DeleteFile objfolder.path & "\" & objFile.Name,1 End If Next ShowSubfolders objFSO.GetFolder(objStartFolder) Sub ShowSubFolders(Folder) For Each Subfolder in Folder.SubFolders ' Wscript.Echo Subfolder.Path '顯示子資料夾路徑 Set objFolder = objFSO.GetFolder(Subfolder.Path) Set colFiles = objFolder.Files For Each objFile in colFiles '刪除 Thumbs.db 和 acdb.err if objFile.Name="Thumbs.db" or objFile.Name="acdb.err" then objFSO.DeleteFile Subfolder.Path & "\" & objFile.Name elseIf objFile.DateLastModified < Now - 7 Then '顯示完整的文件名 wshshell.popup Subfolder.Path & "\" & objFile.Name,1,"folder.vbs" '刪除7天前的文件 objFSO.DeleteFile Subfolder.Path & "\" & objFile.Name End If Next ' Wscript.Echo ShowSubFolders Subfolder Next End Sub
這個腳本也還有一個問題,就是空的資料夾暫時無法自動刪除,再看看如何處理再說......