We help IT Professionals succeed at work.

vbs to delete and move folder

kwatt562
kwatt562 asked
on
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%\
then
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.
Comment
Watch Question

Test your restores, not your backups...
Expert of the Year 2019
Top Expert 2016
Commented:
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

~bp

Author

Commented:
thank you for that I get error line 1, character 13, expected end of statement?
Bill PrewTest your restores, not your backups...
Expert of the Year 2019
Top Expert 2016

Commented:
How are you running this?  It should be saved as a VBS, and run from a command prompt like:

cscript yourname.vbs

~bp

Author

Commented:
It was an issue with our deployment, tool, apologies, your script worked perfectly. Thanks so much.