如何确定何时在VBScript中完成复制?
问题描述:
有谁知道一种方法来确定文件副本何时在VBScript中完成?我使用以下复制:如何确定何时在VBScript中完成复制?
set sa = CreateObject("Shell.Application")
set zip = sa.NameSpace(saveFile)
set Fol = sa.NameSpace(folderToZip)
zip.copyHere (Fol.items)
答
Do Until zip.Items.Count = Fol.Items.Count
WScript.Sleep 300
Loop
当循环结束时,您的副本完成。
但是,如果您只想复制而不是zip,则FSO或WMI更好。
如果你想压缩文件并且想要它们在文件中,你必须自己创建压缩文件,首先使用右边的头文件。否则你只能得到压缩文件/文件夹IIRC。类似这样的:
Set FSO = CreateObject("Scripting.FileSystemObject")
Set File = FSO.OpenTextFile(saveFile, 2, True)
File.Write "PK" & Chr(5) & Chr(6) & String(18, Chr(0))
File.Close
Set File = Nothing
Set FSO = Nothing
在OpenTextFile中的2是ForWriting。
答
Const FOF_CREATEPROGRESSDLG = &H0&
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set fso = CreateObject("Scripting.FileSystemObject")
strSource = " " ' Source folder path of log files
strTarget = " .zip" ' backup path where file will be created
AddFilesToZip strSource,strTarget
Function AddFilesToZip (strSource,strTarget)
Set r=fso.GetFolder(strSource)
set file = fso.opentextfile(strTarget,ForWriting,true)
file.write "PK" & chr(5) & chr(6) & string(18,chr(0))
file.Close
Set shl = CreateObject("Shell.Application")
i = 0
For each f in r.Files
If fso.GetExtensionName(f) = "log" Or fso.GetExtensionName(f) = "Log" Or fso.GetExtensionName(f) = "LOG" Then
shl.namespace(strTarget).copyhere(f.Path)', FOF_CREATEPROGRESSDLG
Do until shl.namespace(strTarget).items.count = i
wscript.sleep 300
Loop
End If
i = i + 1
Next
set shl = Nothing
End Function
潜在可能是压缩,因此不使用FSO – tloach 2008-09-29 18:23:22