Having a problem with a script I've been working on. I thought it was functionaly complete and rolled it out to the end user that needed it, but the user ran into a situation today that I'd like to get fixed. It just needs a bit of error checking, but I'm not sure where to roll it in. The problem is in the recursive search for a "source" file. If the script can't find the file specified, it just quits. I need it to throw a message along the lines that the file couldn't be found. Script pasted below:
dtmStart = Now()
strCaseFile = InputBox("Enter the case number for the file to unpurge:" & Chr(13) & "(This may take several minutes. You will be prompted upon completion)","WLF Archive File UnPurge Tool", "Enter 6 digit Case number here") & ".tif"
strCaseDb = Left(strCaseFile,6)
If strCaseFile = "" Then
WScript.Quit
Else
' WScript.Echo strCaseFile
End If
Set objExplorer = WScript.CreateObject("InternetExplorer.Application")
objExplorer.Navigate "about:blank"
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width=600
objExplorer.Height = 200
objExplorer.Left = 0
objExplorer.Top = 0
objExplorer.Document.Title = "WLF Case UnPurge Tool"
Do While (objExplorer.Busy)
WScript.Sleep 200
Loop
objExplorer.Visible = 1
objExplorer.Document.Body.bgcolor = "green"
Call DBUpdate
Call folderlist("\\sup02\archive", strCaseFile, "\\wlf-dc1\CaseLib")
WScript.Quit
Sub folderlist(searchFolder,toFind, destDir)
objExplorer.Document.Body.InnerHTML = "Finding File In Archive. " _
& "This may take several minutes to complete."
On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
Dim myFolder,Subfolder,mySubfolders, File, tmpFileName
If (Right(searchFolder,1) <> "\") Then
searchFolder = searchFolder & "\"
End If
Set myFolder = fso.GetFolder(searchFolder)
Set mySubFolders = myFolder.SubFolders
For Each File In MyFolder.Files 'Loop through the files in the folder
'WScript.Echo ("File: '" & File.Name & "'")
toFind = LCase(toFind)
tmpFileName = LCase(File.Name)
If (tmpFileName = toFind) Then
' WScript.Echo (Left(file.path, Len(file.path) - Len(file.name) ) )
' WScript.Echo (File.Size & " bytes" & vbtab & File.Type & vbtab & File.DateCreated & vbtab & File.name )
If (Right(destDir,1) <> "\") Then
destDir = destDir & "\"
End If
If fso.FileExists(destDir & file.name) Then
' WScript.Echo destDir & file.name & " already exists in CaseLib."
MsgBox destDir & file.name & " already exists.", 0
WScript.Quit
Else
'WScript.Echo ("fso.CopyFile " & File.path & ", " & destDir)
fso.CopyFile File.path, destDir, True
Set objShell = CreateObject("Wscript.Shell")
objShell.Run "Attrib.exe +r " & destDir & "\" & file.name, 0, True
dtmEnd = Now()
MsgBox file.name & " has been restored to CaseLib." & " Operation completed in " & DateDiff("s", dtmStart, dtmEnd) & " seconds.", 0
' objExplorer.Document.Body.InnerHTML = file.name & " has been restored to CaseLib." & " Operation completed in " & DateDiff("s", dtmStart, dtmEnd) & " seconds."
objExplorer.Quit
End If
If (Err.Number <> 0) Then
MsgBox "Error: " & Err.Number & vbcrlf & Err.Description & vbcrlf & Err.Source
End If
End If
Next
For Each Subfolder In myFolder.SubFolders
Call folderlist(Subfolder.path, toFind, destDir)
Next
End Sub
Sub DBUpdate
objExplorer.Document.Body.InnerHTML = "Restoring Entry in CaseFile Database. " _
& "This may take several minutes to complete."
WScript.Sleep 5000
Dim oConn
Set oConn = CreateObject("ADODB.Connection")
oConn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=\\wlf-dc1\CaseDatabase\Case_Files.mdb"
' execute query. Must have space after Procedure Name
oConn.Execute "exec RetPurgProc " & strCaseDB
' Clean up
oConn.Close
' oConn.Quit
Set oConn = Nothing
objExplorer.Document.Body.InnerHTML = "Case File " & strCaseDB & " has been restored to the CaseFile database. It will be usable in Caseweb after the next Day-End run"
WScript.Sleep 5000
End Sub
dtmStart = Now()
strCaseFile = InputBox("Enter the case number for the file to unpurge:" & Chr(13) & "(This may take several minutes. You will be prompted upon completion)","WLF Archive File UnPurge Tool", "Enter 6 digit Case number here") & ".tif"
strCaseDb = Left(strCaseFile,6)
If strCaseFile = "" Then
WScript.Quit
Else
' WScript.Echo strCaseFile
End If
Set objExplorer = WScript.CreateObject("InternetExplorer.Application")
objExplorer.Navigate "about:blank"
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width=600
objExplorer.Height = 200
objExplorer.Left = 0
objExplorer.Top = 0
objExplorer.Document.Title = "WLF Case UnPurge Tool"
Do While (objExplorer.Busy)
WScript.Sleep 200
Loop
objExplorer.Visible = 1
objExplorer.Document.Body.bgcolor = "green"
Call DBUpdate
Call folderlist("\\sup02\archive", strCaseFile, "\\wlf-dc1\CaseLib")
WScript.Quit
Sub folderlist(searchFolder,toFind, destDir)
objExplorer.Document.Body.InnerHTML = "Finding File In Archive. " _
& "This may take several minutes to complete."
On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
Dim myFolder,Subfolder,mySubfolders, File, tmpFileName
If (Right(searchFolder,1) <> "\") Then
searchFolder = searchFolder & "\"
End If
Set myFolder = fso.GetFolder(searchFolder)
Set mySubFolders = myFolder.SubFolders
For Each File In MyFolder.Files 'Loop through the files in the folder
'WScript.Echo ("File: '" & File.Name & "'")
toFind = LCase(toFind)
tmpFileName = LCase(File.Name)
If (tmpFileName = toFind) Then
' WScript.Echo (Left(file.path, Len(file.path) - Len(file.name) ) )
' WScript.Echo (File.Size & " bytes" & vbtab & File.Type & vbtab & File.DateCreated & vbtab & File.name )
If (Right(destDir,1) <> "\") Then
destDir = destDir & "\"
End If
If fso.FileExists(destDir & file.name) Then
' WScript.Echo destDir & file.name & " already exists in CaseLib."
MsgBox destDir & file.name & " already exists.", 0
WScript.Quit
Else
'WScript.Echo ("fso.CopyFile " & File.path & ", " & destDir)
fso.CopyFile File.path, destDir, True
Set objShell = CreateObject("Wscript.Shell")
objShell.Run "Attrib.exe +r " & destDir & "\" & file.name, 0, True
dtmEnd = Now()
MsgBox file.name & " has been restored to CaseLib." & " Operation completed in " & DateDiff("s", dtmStart, dtmEnd) & " seconds.", 0
' objExplorer.Document.Body.InnerHTML = file.name & " has been restored to CaseLib." & " Operation completed in " & DateDiff("s", dtmStart, dtmEnd) & " seconds."
objExplorer.Quit
End If
If (Err.Number <> 0) Then
MsgBox "Error: " & Err.Number & vbcrlf & Err.Description & vbcrlf & Err.Source
End If
End If
Next
For Each Subfolder In myFolder.SubFolders
Call folderlist(Subfolder.path, toFind, destDir)
Next
End Sub
Sub DBUpdate
objExplorer.Document.Body.InnerHTML = "Restoring Entry in CaseFile Database. " _
& "This may take several minutes to complete."
WScript.Sleep 5000
Dim oConn
Set oConn = CreateObject("ADODB.Connection")
oConn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=\\wlf-dc1\CaseDatabase\Case_Files.mdb"
' execute query. Must have space after Procedure Name
oConn.Execute "exec RetPurgProc " & strCaseDB
' Clean up
oConn.Close
' oConn.Quit
Set oConn = Nothing
objExplorer.Document.Body.InnerHTML = "Case File " & strCaseDB & " has been restored to the CaseFile database. It will be usable in Caseweb after the next Day-End run"
WScript.Sleep 5000
End Sub