2016-03-07 78 views
1

我想從一個位置複製配置文件並將它們覆蓋到另一個位置。以下是我的示例腳本,任何人都可以幫助我得到這個工作嗎?使用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" 

回答

1

有點不清楚的問題。但是,在接下來評論代碼片段被描述爲基本改進:

''' 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" 
相關問題