4

VBScript でファイルのコピーがいつ完了したかを判断する方法を知っている人はいますか? 以下を使用してコピーしています。

set sa = CreateObject("Shell.Application")  
set zip = sa.NameSpace(saveFile)  
set Fol = sa.NameSpace(folderToZip)  
zip.copyHere (Fol.items)
4

3 に答える 3

6
Do Until zip.Items.Count = Fol.Items.Count
    WScript.Sleep 300
Loop

ループが終了すると、コピーが終了します。

ただし、圧縮せずにコピーするだけの場合は、FSO または WMI の方が適しています。

圧縮してファイルに入れたい場合は、正しいヘッダーを最初に付けて、自分で zip ファイルを作成する必要があります。それ以外の場合は、圧縮されたファイル/フォルダー 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 です。

于 2008-09-29T18:21:31.757 に答える
2

で Copy メソッドを使用すると、うまくいく場合がありますFileSystemObject。コピーに使用しましたが、ブロッキングコールです。

于 2008-09-29T18:18:03.450 に答える
0
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
于 2015-02-17T15:32:24.363 に答える