Link to home
Start Free TrialLog in
Avatar of itagent007
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("Scripting.FileSystemObject")
Dim objSourceFldr: Set objSourceFldr=objFSO.GetFolder("\\ComputerA\TempA")
strDstFldr="\\ComputerB\TempB"

For Each file in objSourceFldr.Files
      objFSO.CopyFile file.Path, strDstFldr
Next
Set objFSO=Nothing
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Avatar of itagent007
itagent007

ASKER

Sorry, new to this. But how do I convert that VBA code to VBScript?
ASKER CERTIFIED SOLUTION
Avatar of jmundsack
jmundsack
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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.