VB脚本删除文件创建日期+异常

时间:2017-12-08 09:13:52

标签: vbscript

我想使用VB脚本删除超过60天的文件和文件夹。

如何在脚本中排除特定文件夹?

' Global FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Start at the root
DoFolder "H:\Werk\Testfolder"

' Recursive function
Sub DoFolder(strFolder)

With objFSO.GetFolder(strFolder)

    For Each objFile In .Files
        If objFile.DateCreated < Date - 60 Then objFile.Delete
    Next

    For Each objFolder In .SubFolders
        DoFolder objFolder.Path
    Next

    ' Checked every file and subfolder. If this folder is empty, remove it...
   If .Files.Count = 0 Then If .SubFolders.Count = 0 Then .Delete

End With

End Sub

我想排除以下内容:

H:\ Werk \ Testfolder \ Favorieten

H:\ WERK \ Testfolder \ OneNote的-notitieblokken

我该怎么做?

1 个答案:

答案 0 :(得分:0)

For Each objFolder In .SubFolders
    If objfolder.path <> "c:\whatever\whatever.ext" then
        DoFolder objFolder.Path
    End If
Next

你是怎么做的。