2

My code searches folders and sub folders. I want to be able to exclude open files or system files when processing each file in these folders. Any help would be great!

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

1 Answers1

1

I think GetAttr function should help you.

This should exclude any hidden or opened files:

For Each oFile In oFolder.Files 
    If (GetAttr(oFile) And vbHidden) = 0 Then 'Process files that are not hidden
        '
        '~~> Do what you want
        '
Next oFile
Muhid
  • 91
  • 5