Opfølgning: Automatisk med Z interval copy fil fra X til Y
Opfølgning på http://www.eksperten.dk/spm/456886Beskrivelse af programmet kan læses samme sted...
'---------------------------------------------------------------------
Option Explicit
Dim WshShell, oFS, Source, Destination, oCatalog, file, oFiles, LogFile, SleepTimer
Set WshShell = CreateObject("WScript.Shell")
Set oFS = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1, ForWriting = 2, ForAppending = 8
If WScript.Arguments.Count < 3 Then
WScript.Echo "Error in command. For Right use, type:" & vbCrLf _
& "CScript SpotAndCopy.vbs [TIME] [Source] [Destination] [LogFile]" & vbCrLF & vbCrLf _
& "EX:" & vbCrLf & "CScript SpotAndCopy.vbs 10 C:\Source C:\Destination C:\logfile.txt"
WScript.Echo SleepTimer
WScript.Quit
End If
SleepTimer = WScript.Arguments(0) 'Time in Seconds
SleepTimer = SleepTimer * 1000
Source = WScript.Arguments(1) '"c:\temp\Source"
Destination = WScript.Arguments(2) '"c:\temp\Destination"
LogFile = WScript.Arguments(3) 'Source & "\LogFile.log"
Set oCatalog = oFS.GetFolder(Source)
Set oFiles = oCatalog.Files
Set LogFile = oFS.OpenTextFile(LogFile, ForAppending, True)
Do
For Each file In oFiles
If file.Size > 0 Then
Copy(file)
End If
Next
WScript.Sleep SleepTimer
Loop
WshShell = "Nothing"
oFS = "Nothing"
LogFile.Close
LogFile = "Nothing"
'---------------------------------------------------------------------
Function Copy(file)
Dim DestinationFile, DF
DestinationFile = Right(file, (Len(file)-InStrRev(file, "\", -1, vbTextCompare)))
If Not oFS.FileExists(Destination & "\" & DestinationFile) Then
oFS.CopyFile file, Destination & "\" & DestinationFile, True
If Err.Number = 0 Then
Log(DestinationFile & " Has been copied.")
Else
Log("Copy og file " & file & " has failed with the following message: " & Err.Description)
End If
Err.Clear
Else
Set DF = oFS.GetFile(Destination & "\" & DestinationFile)
If file.DateLastModified <> DF.DateLastModified Then
oFS.CopyFile file, Destination & "\" & DestinationFile, True
If Err.Number = 0 Then
Log(DestinationFile & " Has been copied.")
Else
Log("Copy og file " & file & " has failed with the following message: " & Err.Description)
End If
Err.Clear
End if
End If
End Function
'---------------------------------------------------------------------
Function Log(Msg)
LogFile.WriteLine Time & " " & Date & " " & Msg
End Function
'---------------------------------------------------------------------
Program:
Hvis Source eller Dest ikke er tilgængeligt så går programmet i stå ?
Ønsket tilretning:
At få programmet til at på en eller anden måde checke om Source eller Dest er tilgængelig undervejs uden at programmet "dør" ved (forsøg på) copy process? Og så automatisk prøve igen efter lidt tid...
I mit tilfælde er Source og Dest et mappet netværksdrev (på hver sin server) og Logfil er på en tredie server !!!
Jeg bruger pt. 15 sek. interval.
I retning af:
If not exist [Source] or if not exist [Dest] skip_copy ...
eller hvad det kaldes i dette sprog...
Skriv for yderligerer info...