在文件夹中搜索时排除系统文件并打开文件

时间:2018-08-02 15:14:03

标签: vba excel-vba

我的代码搜索文件夹和子文件夹。处理这些文件夹中的每个文件时,我希望能够排除打开的文件或系统文件。任何帮助都会很棒!

Dim fso, oFolder, oSubfolder, oFile, queue As Collection

Set fso = CreateObject("Scripting.FileSystemObject")
Set queue = New Collection
queue.Add fso.GetFolder("folderpath")

Do While queue.Count > 0
    Set oFolder = queue(1)
    queue.Remove 1 'dequeue
    For Each oSubfolder In oFolder.SubFolders
        If UCase(oSubfolder.Name) <> "DO NOT USE" Then
            queue.Add oSubfolder 'enqueue
        Else
        End If
    Next oSubfolder
    For Each oFile In oFolder.Files
        'Process each file but exclude files such as "~xxxxxx" or thumbs.db or xxxx.tmp files
    Next oFile
Loop

0 个答案:

没有答案