itagent007
asked on
How do you write VBScript to copy subfolders and files from one folder to another
I want to use a VBScript to copy all the contents (subfolders and files) from FolderA to FolderB. I found this code on this site to copy files, but not the subfolders. Is there a way to do that through VBScript?
Dim objFSO:Set objFSO=CreateObject("Scrip ting.FileS ystemObjec t")
Dim objSourceFldr: Set objSourceFldr=objFSO.GetFo lder("\\Co mputerA\Te mpA")
strDstFldr="\\ComputerB\Te mpB"
For Each file in objSourceFldr.Files
objFSO.CopyFile file.Path, strDstFldr
Next
Set objFSO=Nothing
Dim objFSO:Set objFSO=CreateObject("Scrip
Dim objSourceFldr: Set objSourceFldr=objFSO.GetFo
strDstFldr="\\ComputerB\Te
For Each file in objSourceFldr.Files
objFSO.CopyFile file.Path, strDstFldr
Next
Set objFSO=Nothing
Check in here http://www.rondebruin.nl/folder.htm#Copy
ASKER
Sorry, new to this. But how do I convert that VBA code to VBScript?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
jmundsack is right, the CopyFolder method will work. It exists as a standard method in VBScript, and the link that was posted adds some error checking to that.
Regards,
Rob.
Regards,
Rob.
Thank you for the points, but I feel bad about being awarded full points on this--jpaulino gave the code, and all I did was indicate how to convert VBA to VBScript.