Who do I make the check out to ...

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
BlackWisdom
Pro Scripter
Posts: 58
Joined: Thu Oct 16, 2003 12:53 am

Who do I make the check out to ...

Post by BlackWisdom » Tue May 17, 2005 9:11 pm

ok guys Im authorized to pay to get this issue resolved:

I have tried everything, and I still cant get this script to ignore the script control time out. after 5 seconds I still get the time out message even though Im using the "Let>VBS_TIMEOUT=40000" statement - which I have placed in several places to no avail. Based on the way its acting its possible the script may be stuck in a loop somewhere - bit I dont see it. I can be reached at [email protected]. Here is the script which I have modified several times:


Let>VBS_TIMEOUT=40000
VBStart
Dim BackupFilesSigDate, filesys, oFolder, srcfolder, tgtfolder, oFile
BackupFilesSigDate = Date -1
srcfolder = "C:\"
tgtfolder = "24hrBackup\"
Set filesys = CreateObject("Scripting.FileSystemObject")
Set oFolder = filesys.GetFolder(srcfolder)

If Err.Number 0 Then
Wscript.echo "The Source Folder does not exists. Operation aborted."
Set oFolder = Nothing
Set filesys = Nothing
Else
ScanTree(srcfolder)
End If

Set oFile = Nothing
Set oFolder = Nothing
Set filesys = Nothing

Function ScanTree(ByVal sRoot)
Dim oRoot
Dim SubFolder

On Error Resume Next

If Not IsEmpty(sRoot) And sRoot tgtfolder Then
Set oRoot = filesys.GetFolder(sRoot)
For Each SubFolder In oRoot.SubFolders
If Err.Number 0 Then
Err.Clear
Else
CheckFiles(oRoot)
If Not IsEmpty(SubFolder) Then
'-- use recursion to get the entire tree...
ScanTree SubFolder
End If
End If
Next
End If

On Error Goto 0
End Function

Sub CheckFiles(oFolder)
Dim oFile

On Error Resume Next

For Each oFile In oFolder.Files
If Err.Number 0 Then ' if we got an error, just skip this entry
Err.Clear
ElseIf DateDiff("d", BackupFilesSigDate, oFile.DateCreated) = 0 Then
filesys.copyfile oFile.Path, tgtfolder & "\" & oFile.Name, True
End If
Next

On Error Goto 0
End Sub
VBEnd

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Tue May 17, 2005 9:31 pm

Whoa - that won't work!

Try the following version. If nothing else this will give more helpful error messages:

VBStart
Dim BackupFilesSigDate, filesys, oFolder, srcfolder, tgtfolder, oFile

Sub CheckFiles(oFolder)
Dim oFile

'On Error Resume Next

For Each oFile In oFolder.Files
If Err.Number 0 Then ' if we got an error, just skip this entry
Err.Clear
ElseIf DateDiff("d", BackupFilesSigDate, oFile.DateCreated) = 0 Then
filesys.copyfile oFile.Path, tgtfolder & "\" & oFile.Name, True
End If
Next

On Error Goto 0
End Sub

Function ScanTree(ByVal sRoot)
Dim oRoot
Dim SubFolder
'On Error Resume Next

If Not IsEmpty(sRoot) And sRoot tgtfolder Then

Set oRoot = filesys.GetFolder(sRoot)
For Each SubFolder In oRoot.SubFolders
If Err.Number 0 Then
Err.Clear
Else
CheckFiles(oRoot)
If Not IsEmpty(SubFolder) Then
'-- use recursion to get the entire tree...
ScanTree SubFolder
End If
End If
Next
End If

On Error Goto 0
End Function

Sub Main
BackupFilesSigDate = Date -1
srcfolder = "C:\"
tgtfolder = "24hrBackup\"
Set filesys = CreateObject("Scripting.FileSystemObject")
Set oFolder = filesys.GetFolder(srcfolder)

If Err.Number 0 Then
MsgBox "The Source Folder does not exists. Operation aborted."
Set oFolder = Nothing
Set filesys = Nothing
Else
ScanTree(srcfolder)
End If

Set oFile = Nothing
Set oFolder = Nothing
Set filesys = Nothing
End Sub

VBEnd

VBRun>Main

In Macro Scheduler VBScript code must be executed initially by VBRun or VBEval. WScript.Echo won't work because WScript doesn't exist in Macro Scheduler. WScript is a scripting host but in this case Macro Scheduler is the host. So I've replaced WScript.Echo with MsgBox.

Hope this gets you started.
MJT Net Support
[email protected]

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts