VBScript에서 복사가 완료되는시기를 결정하는 방법은 무엇입니까?

StackOverflow https://stackoverflow.com/questions/149956

  •  02-07-2019
  •  | 
  •  

문제

누구든지 파일 사본이 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가 더 좋습니다.

당신이 지핑 중이고 파일로 그들을 원한다면 오른쪽 헤더를 먼저 가지고 지퍼 파일을 직접 만들어야합니다. 그렇지 않으면 압축 파일/폴더 만 얻을 수 있습니다. 이 같은:

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입니다.

다른 팁

복사 방법을 사용하여 더 나은 행운을 누릴 수 있습니다. FileSystemObject. 복사에 사용했는데 차단 호출입니다.

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top