使用VBS将多个文本文件复制到多个位置
问题描述:
我想从一个位置复制配置文件并将它们覆盖到另一个位置。以下是我的示例脚本,任何人都可以帮助我得到这个工作吗?使用VBS将多个文本文件复制到多个位置
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"
答
有点不清楚的问题。但是,在接下来评论代码片段被描述为基本改进:
''' 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"