abenitez77
IS-IT--Management
I have my source folders that are named like this "12345", "00345", "28429" (folder name is 5 digit numbers). My destination folders are like this "00001X12345", "00002X00345", etc...
The last 5 spaces of the destination folder names match up with the source folder names. In some cases the folders don't exists in the destination folders and I have to just copy the entire folder to the path of the destination (or create the new folder and copy all the files in them to the new location). I can copy the existing folders but am having trouble finishing it to copy folders that don't exist in the destination folder path.
I need to create the new folder in the destination path and copy all the files from source folder to that new path.
This is the code I have so far:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set SRCobjFolder = objFSO.GetFolder("C:\Data\BCF\Images\")
Set SRCcolSubfolders = SRCobjFolder.Subfolders
Set DESTobjFolder = objFSO.GetFolder("C:\Data\ANP\Images\")
Set DESTcolSubfolders = DESTobjFolder.Subfolders
dim filesys
Dim Folder
Set filesys=CreateObject("Scripting.FileSystemObject")
For Each SRCobjSubfolder in SRCcolSubfolders
For Each DESTobjSubfolder In DESTcolsubfolders
' Check if folder exists in the destination path.
If DESTobjsubfolder.Name = Right(SRCobjsubfolder.Name,7) Then
' filesys.CopyFolder SRCobjsubfolder.path , DESTobjsubfolder.path
For Each file In SRCobjSubfolder.Files
objFSO.CopyFile file.Path, DESTobjSubfolder & "\"
Next
End If
Next
Next
wscript.echo "Done"
Set objFSO = Nothing
Set filesys = Nothing
The last 5 spaces of the destination folder names match up with the source folder names. In some cases the folders don't exists in the destination folders and I have to just copy the entire folder to the path of the destination (or create the new folder and copy all the files in them to the new location). I can copy the existing folders but am having trouble finishing it to copy folders that don't exist in the destination folder path.
I need to create the new folder in the destination path and copy all the files from source folder to that new path.
This is the code I have so far:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set SRCobjFolder = objFSO.GetFolder("C:\Data\BCF\Images\")
Set SRCcolSubfolders = SRCobjFolder.Subfolders
Set DESTobjFolder = objFSO.GetFolder("C:\Data\ANP\Images\")
Set DESTcolSubfolders = DESTobjFolder.Subfolders
dim filesys
Dim Folder
Set filesys=CreateObject("Scripting.FileSystemObject")
For Each SRCobjSubfolder in SRCcolSubfolders
For Each DESTobjSubfolder In DESTcolsubfolders
' Check if folder exists in the destination path.
If DESTobjsubfolder.Name = Right(SRCobjsubfolder.Name,7) Then
' filesys.CopyFolder SRCobjsubfolder.path , DESTobjsubfolder.path
For Each file In SRCobjSubfolder.Files
objFSO.CopyFile file.Path, DESTobjSubfolder & "\"
Next
End If
Next
Next
wscript.echo "Done"
Set objFSO = Nothing
Set filesys = Nothing