vbs to delete and move folder

Does anyone have any code they can share to perform this task
If this this folder exists - %localappdata%\int42, delete it
then copy folder \\servername\int42 to %localappdata%\
if this folder exists %localappdata%\int43, delete it
then copy folder \\servername\int43 to %localappdata%\

Hope that's clear and someone has done something similar.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
Give this a try:

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")

DoCopy "\\servername\int42", objShell.ExpandEnvironmentStrings("%LOCALAPPDATA%\int42")
DoCopy "\\servername\int43", objShell.ExpandEnvironmentStrings("%LOCALAPPDATA%\int43")

Sub DoCopy (strFromFolder, strToFolder)
   If objFSO.FolderExists(strToFolder) Then
      objFSO.DeleteFolder strToFolder
   End If
   objFSO.CopyFolder strFromFolder, strToFolder
End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kwatt562Author Commented:
thank you for that I get error line 1, character 13, expected end of statement?
Bill PrewIT / Software Engineering ConsultantCommented:
How are you running this?  It should be saved as a VBS, and run from a command prompt like:

cscript yourname.vbs

kwatt562Author Commented:
It was an issue with our deployment, tool, apologies, your script worked perfectly. Thanks so much.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.