Pregunta

¿Alguien sabe de un método para determinar cuándo se completa una copia de archivo en VBScript? Estoy usando lo siguiente para copiar:

set sa = CreateObject("Shell.Application")  
set zip = sa.NameSpace(saveFile)  
set Fol = sa.NameSpace(folderToZip)  
zip.copyHere (Fol.items)
¿Fue útil?

Solución

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

Cuando finaliza el bucle, la copia finaliza.

Pero si solo desea copiar y no comprimir, FSO o WMI es mejor.

Si está comprimiendo y desea que estén en un archivo, debe crear el archivo zip usted mismo, con el encabezado correcto primero. De lo contrario, solo obtendrá archivos / carpetas comprimidos IIRC. Algo como esto:

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

El 2 en OpenTextFile es ForWriting.

Otros consejos

Puede que tenga mejor suerte usando el método Copiar en un FileSystemObject . Lo he usado para copiar, y es una llamada de bloqueo.

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
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top