(Solved) – CopyFolder if folder does not exist with wildcard

(solved)-–-copyfolder-if-folder-does-not-exist-with-wildcard

I have a macro that seaches one or multiple folders based on a name with wildcard to a destination folder. I’m trying to get it to skip the copying if the folder already exists in the destination folder but if I set it to False it will stop copying after it.
If I try to do it with the Dir( vbDirectory), it only returns the first folder with the Name inside.
The FolderExists also returns only the first match. I also tried to change the location of the CopyFolder line but no luck here.

At this moment, the macro always copies all the folders with the name inside.

    On Error Resume Next
    For Each f In fsFD.SubFolders
        n = n   1
        ReDim Preserve vR(1 To n)
        With f
            vR(n) = f.Path
           'Debug.Print vR(n)
           FS.CopyFolder vR(n) & "https://stackoverflow.com/" & Name & "Lay*" & Wb.Sheets("Sheet3").Range("B1") & "*", MAIN_FOLDER & "LayLay", False


        'FolderName = Dir(vR(n) & "https://stackoverflow.com/" & Name & "Lay*" & Wb.Sheets("Sheet3").Range("B1") & "*", vbDirectory)
  ' Debug.Print FolderName

        End With

        'Debug.Print FS.FolderExists(MAIN_FOLDER & "LayLay*" & Wb.Sheets("Sheet3").Range("B1") & "*")




   'FS.CopyFolder vR(n) & "https://stackoverflow.com/" & Name & "Lay*" & Wb.Sheets("Sheet3").Range("B1") & "*", MAIN_FOLDER & "LayLay"


    Next f

Leave a Reply

Your email address will not be published. Required fields are marked *