Reputation: 75
I would like to copy config files from one location and overwrite them to another location. Below is my example script, can anyone help me get this working please?
strFileToCopy = "C:\Users\newtons\Desktop\Strat App 4 point to Pan 3.txt"
strFolder = "C:\Users\newtons\Desktop\test\"
Const OverwriteExisting = TRUE
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strFolder) Then
objFSO.CopyFile strFileToCopy, strFolder, OverwriteExisting
Else
Wscript.Echo "Target Folder does not exist."
End If
strFileToCopy = "C:\Users\newtons\Desktop\Stat App 4 point to Pan 3.txt"
strFolder = "C:\Users\newtons\Desktop\test 2\"
Const OverwriteExisting = TRUE
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strFolder) Then
objFSO.CopyFile strFileToCopy, strFolder, OverwriteExisting
Else
Wscript.Echo "Target Folder does not exist."
End If
Wscript.Echo "App 4 is now pointing to Pan 3"
Upvotes: 1
Views: 1624
Reputation: 30123
A bit unclear question. However, in next commented code snippet are described basic improvements:
''' disable error handling; show error and stop instead
On Error GoTo 0
Const OverwriteExisting = TRUE
Set objFSO = CreateObject("Scripting.FileSystemObject")
strFileToCopy = "C:\Users\newtons\Desktop\Strat App 4 point to Pan 3.txt"
strFolder = "C:\Users\newtons\Desktop\test\"
If objFSO.FolderExists(strFolder) Then
objFSO.CopyFile strFileToCopy, strFolder, OverwriteExisting
Else
Wscript.Echo "Target Folder does not exist."
End If
strFileToCopy = "C:\Users\newtons\Desktop\Stat App 4 point to Pan 3.txt"
strFolder = "C:\Users\newtons\Desktop\test 2\"
''' you cannot redefine a constant value
''' Const OverwriteExisting = TRUE
''' you need not redefine a variable to the same value
''' Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strFolder) Then
objFSO.CopyFile strFileToCopy, strFolder, OverwriteExisting
Else
Wscript.Echo "Target Folder does not exist."
End If
Wscript.Echo "App 4 is now pointing to Pan 3"
Upvotes: 1