Is there a way to use oFSO.CopyFolder & split() to copy files from more than one directory to another

Viewed 33

I am trying to copy a few folders from different directories into another single directory.

I am using the copy folder method but I get a type mismatch error.

I think it turns the strings into an array but i cannot figure out how to handle the value in the FoldersList variable after that

I am using VBscript

Dim oFSO : Set oFSO = CreateObject("Scripting.FileSystemObject")

Const Folders = "C:\Dest1,C:\Dest2,C:\Dest3"

Dim FoldersList : FoldersList = Split(Folders,",") 

oFSO.CopyFolder(FoldersList), "C:\DestinationDirectory\"
1 Answers

It does turn FolderList into an array but make sure none of those "Dest" folder names contain a comma in their name because your "Split" function will fail then since you chose comma as the delimiter. This code should work correctly for going through your Folderlist:

Dim Folder
For Each Folder in Folderlist
    oFSO.CopyFolder Folder, "C:\DestinationDirectory"
Next
Related