简体   繁体   中英

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

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\"

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM