I have been trying to debug a VBScript that runs on a schedule every 10 minutes to move folders and their contents from one network location to another.
I don’t have access to the console, only the folder where the script lives (which is also where it writes a log file). I can see that it’s running, because it writes to the log.
I inherited this script from someone else who has left - VBS is not my native coding language, but I’m comfortably familiar with VBA, which is nearly identical.
Here’s the first bit of the script:
On Error Resume Next ForAppending = 8 Scriptversion = 1.7 Set objShell = wscript.CreateObject("WScript.Shell") Set objFSO = CreateObject("Scripting.FileSystemObject") TempFolderPath = "\\[ip address redacted]\filesIn" 'no trailing backslash - this is the location of the incoming folders Set ObjOutFile = objFSO.OpenTextFile("\\[server path redacted]\Moved Files List.txt", ForAppending, True) ObjOutFile.WriteLine(vbCRLF & Now & "- Script version " & scriptversion) Set objFolder = objFSO.GetFolder(TempFolderPath) If objFolder.Subfolders.count = 1 Then ObjOutFile.WriteLine("Nothing to do") Wscript.Quit End If ObjOutFile.WriteLine("There are " & objFolder.Subfolders.count & " folder(s) to process.") For Each objSubfolder In objFolder.Subfolders [code here that moves folders and their contents, etc.
Everything is working, except the Wscript.Quit
If there’s only 1 folder in the source location, I want it to report ‘nothing to do’, then quit (the single folder is one I know must not be moved - ignored by the later code), but when I examine the log file, I’m seeing this:
10/01/2014 16:30:42 Script version 1.7 Nothing to do **There are 1 folder(s) to process. --------- Next folder is: Archive Archive is out of scope for this job**
None of the graped log entries should ever appear if the first line is ‘nothing to do’ - because the code that writes ‘nothing to do’ is immediately followed by Wscript.Quit
So what could be amiss here?