VBScript Copy File

2007-07-18 12:38 am
我寫了一些vbscript, 想copy 一些files 到指定的地方, 我的script 是這樣的:
set objShell = CreateObject("WScript.Shell")
objShell.Run "XCOPY c:\\file1.txt c:\\temp\\ /Y"
objShell.Run "XCOPY c:\\file2.txt c:\\temp\\ /Y"

當我run script 時, 發現2個xcopy 的動作同時進行, 有沒有方法可以完成copy file1.txt 後, 才開始 copy file2.txt 呢?

謝謝

回答 (2)

2007-07-18 11:23 am
✔ 最佳答案
點解你唔用FileSystemObject??????
set fs =createobject("Scripting.FileSystemObject")
fs.copyfile "temp_patch\backup.exe","patch\Patch.exe"
fs.copyfile "temp_patch\version.txt","patch\Version.txt"
fs.copyfile "temp_patch\Product.log","patch\Product.log"
msgbox "Patch updated"
咁樣咪解決左你既問題囉=.=
2007-07-18 7:38 am
Using WScript.Shell, control is passed over to the Kernel and you have no control over the file system operation.

改用 FileSystemObject

Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next ' in case file does not exist, delete fails
fso.DeleteFile("c:\temp\file1.txt", True) ' delete read-only file
On Error GoTo 0 ' cancel error handler
fso.CopyFile "c:\file1.txt", "c:\temp", True ' overwrite existing file
' the code block below is not necessary but no harm trying
' Begin
Do
If fso.FileExists("c:\temp\file1.txt")
Exit Do
End If
Loop
' End
fso.CopyFile "c:\file2.txt", "c:\temp", True


收錄日期: 2021-04-26 13:13:18
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20070717000051KK03080

檢視 Wayback Machine 備份