VB-Skript-Dateien Kopieren und Fortschrittsbalken

Mein code für das kopieren von Dateien von der Quelle zum Ziel funktioniert und was ich versuche zu tun, ist nur kopieren Sie Dateien, wenn Sie neuer sind, oder mit einem anderen Namen.
Name der Datei Beispiel abc1.txt und der folgenden Woche werden diese ersetzt mit den source-Ordner zu abc2.txt
Hier ist die VB Script-code.

`

Dim intFCount, FSO, strSrcFolder, strDestFolder, strSource, FC, i, intPercentComplete

    i = 0
    intFCount = 0
    intPercentComplete = 0
    Set FSO = CreateObject("Scripting.FileSystemObject")

    strSrcFolder = "\\server\DATA\Production\RUM\"
    strDestFolder = "E:\DATA\Production\test\"

    set strSource = FSO.GetFolder(strSrcFolder)
    set FC = strSource.Files

    for each file in FC
        intFCount = intFCount + 1
    Next

    For Each file in FC
        FSO.CopyFile file, strDestFolder
        i = i + 1
    Next
    2.  I was able to find some progress bar vbs or hta script but struggling to incorporate my copy script to display the progress.  
    Here is the progress bar .hta script found on the net
    <html>
    <head>
    <title id="title">ProgressBar 2.1</title>
    <HTA:APPLICATION ID="porgbar" APPLICATIONNAME="progbartest">
    <script language="vbscript">

    Public x,y, MyTitle, iTimerID, KeepGoing

    Sub Window_Onload
    MyTitle = document.Title
    id("ProgBarToDo").innerText = String(80, "_") & "|"  
    window.ResizeTo 720, 200       
    x=0       
    y=35     
    End Sub

    Sub Go
    '---FOR TEST ONLY---
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set oof = fso.CreateTextFile("testpb.vbs", True)
    oof.WriteLine "wscript.sleep WScript.Arguments(0)"  
    oof.Close
    Set WshShell = CreateObject("WScript.Shell")
    '----END OF TEST ONLY----

    Progress(1)
    Do Until x=y
    x=x+1
    WshShell.Run "testpb.vbs 250",1,True  '----FOR TEST ONLY
    If KeepGoing = False Or window.screenTop > 10000 Then 
    Exit Do
    End If
    Loop
    Progress(0)
    End Sub

    Sub Progress(v)
    Select Case v
    Case 0  
    window.clearInterval(iTimerID)  
    iTimerID =""             
    id("BtnGo").disabled = False       
    id("BtnCancel").disabled = True    
    id("BtnExit").disabled = False     
    Progress(2)            
    MsgBox "Operation finished.",,MyTitle

    Case 1  
    iTimerID = window.setInterval("Progress(2)", 500)    
    id("BtnGo").disabled = True        
    id("BtnCancel").disabled = False   
    id("BtnExit").disabled = True      
    KeepGoing = True
    Progress(2)         

    Case 2  
    document.Title = FormatPercent(x/y, 0) & MyTitle  
    id("ProgBarText").innerText = x & "/" & y  
    d = Round( x / (y/80)  ,0)   
    id("ProgBarDone").innerText = String(d, "_")  
    If d<80 Then   
    id("ProgBarToDo").innerText = String(80-d, "_") & "|"  
    Else     
    id("ProgBarToDo").innerText = "|"  
    End If

    End Select
    End Sub

    Function id(o)
    Set id = document.getElementById(o)
    End Function

    Sub Help
    MsgBox "This is an example of progressbar in HTA written by Fredledingue.",,MyTitle
    End Sub

    </script>
    </head>
    <body bgcolor="GreenYellow">

    <input id="BtnGo"     type="button" value="Go"     onclick="Go">
    <input id="BtnCancel" type="button" value="Cancel" onclick="KeepGoing=False" disabled="True">
    <input id="BtnExit"   type="button" value="Exit"   onclick="window.close">
    <input id="BtnHelp"   type="button" value="Help"   onclick="Help">
    <br>

    Done: <span id="ProgBarText">?</span><br>
    <span id="ProgBarDone" style="background-color:blue"></span>
    <span id="ProgBarToDo" style="background-color:silver"></span>

    </body>
    </html>
    `

Jede Hilfe wird sehr geschätzt.
Vielen Dank,
SS

Gibt es auch einige Vergleich-code finden Sie auf msdn, aber ich muss die Datei abc1.txt existieren auf dem server, wenn nicht kopieren abc2.txt vom server auf die lokale Festplatte. Hier ist der code

enter code here Option Explicit  
Dim objFSO, wshShell  
Set objFSO   = CreateObject("Scripting.FileSystemObject")     
Set wshShell = CreateObject("Wscript.Shell")  
'----------------------------------------------------------------------------------------------------------------------------  
On Error Resume Next 
   ProcessScript  
   If Err.Number <> 0 Then 
      Wscript.Quit  
   End If 
On Error Goto 0  
'----------------------------------------------------------------------------------------------------------------------------  
'Name       : ProcessScript -> Primary Function that controls all other script processing.  
'Parameters : None          ->  
'Return     : None          ->  
'----------------------------------------------------------------------------------------------------------------------------  
Function ProcessScript  
   Dim localFile, serverFile  
   Dim localFileVersion, serverFileVersion  
   localFile  = "C:\rsccc2k\login\login.exe" 
   serverFile = "\\destiny\Install\RSCCC\login.exe" 
   If objFSO.FileExists(localFile) Then 
      If Not GetFileVersion(localFile, localFileVersion) Then 
         Exit Function 
      End If 
      If objFSO.FileExists(serverFile) Then 
         If Not GetFileVersion(serverFile, serverFileVersion) Then 
            Exit Function 
         End If 
      End If 
      If StrComp(localFileVersion, serverFileVersion, vbTextCompare) <> 0 Then 
         On Error Resume Next 
            wshShell.Run "\\destiny\Install\RSCCC\RSCCCInstall.bat", 0, true  
         On Error Goto 0  
      End If 
   End If 
End Function 

'----------------------------------------------------------------------------------------------------------------------------  
'Name       : GetFileVersion -> Enumerates the version number of a file.  
'Parameters : fileSpec       -> Input  : Folder path and file name for the file to enumerate the version number from.  
'           : fileVersion    -> Output : The file version number of input parameter "fileSpec".  
'Return     : GetFileVersion -> Returns False or True and the version number of the file.  
'----------------------------------------------------------------------------------------------------------------------------  
Function GetFileVersion(fileSpec, fileVersion)  
   GetFileVersion = False 
   On Error Resume Next 
      fileVersion = objFSO.GetFileVersion(fileSpec)  
      If Len(fileVersion) = 0 Or Err.Number <> 0 Then 
         Exit Function 
      End If 
   On Error Goto 0  
   GetFileVersion = True 
End Function 
Was ist Ihre Frage?
"was ich versuche zu tun, ist nur kopieren Sie Dateien, wenn Sie neuer sind, oder mit einem anderen Namen," - Nur eine Anregung: Vielleicht wäre es einfacher, einfach spawn eine xcopy oder robocopy Prozess (über WSHShell.Run()), anstatt zu versuchen, eine Datei-Kopier-routine von Grund auf neu?
Jede Hilfe, wie kann ich verwenden Sie xcopy oder robocopy-Prozess (via WSHShell.Run()) bitte

InformationsquelleAutor Zain | 2012-08-06

Schreibe einen Kommentar