Solved

VBScript File Existence Check

Posted on 2011-09-21
3
350 Views
Last Modified: 2012-06-27
I have the following loop that SHOULD be checking for the existence of the file with each loop.  To test, I remove the file, start the program then immediately put the file back in the correct folder.  It loops 5 times but reports the file as not found.
' ==== verify required file exists, indicating previous process has completed
iLoopCtr = 1
lFound = "Y"
If (ucase(GetXMLText("Required\Enabled"))="TRUE") Then
         If GetXMLText("Required\FileName")<> "" Then
              For iLoopCtr = 1 to (GetXMLText("Required\Attempts"))
                    If objFSO.FileExists(GetXMLText("Required\FileName")) = True then
                            iLoopCtr = (GetXMLText("Required\Attempts")+1)
                    Else
                            WScript.Sleep (GetXMLText("Required\WaitTime"))
                            lFound = "N"
                    End If
                Next
          Else
                OutputLogText " - Required File entry missing from XML file - " & NOW
                WScript.Quit
          End If
          If lFound = "N" Then
                 OutputLogText " - Required File (" & GetXMLText("Required\FileName") & ") to proceed NOT found.  Load CANCELLED. - " & NOW
                 WScript.Quit
           Else
                  OutputLogText " - Required File to proceed found.  Load proceeding. - " & NOW
           End If
End if

Open in new window


Is something wrong with the loop?
0
Comment
Question by:kkbenj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 6

Expert Comment

by:jorgedeoliveiraborges
ID: 36576741
Try this, please.

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("C:\FSO\ScriptLog.txt") Then
 Set objFile = objFSO.GetFile("C:\FSO\ScriptLog.txt")
Else
 Wscript.Echo "File does not exist."
End If

Verifying That a File Exists
http://technet.microsoft.com/en-us/library/ee198727.aspx
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 36578039
Hi, I think you have some logic problems.  I think all you need to do is, above this line:
      iLoopCtr = (GetXMLText("Required\Attempts")+1)

add this:
      lFound = "Y"


because what is happening is when the file isn't found in the first loop, lFound becomes "N", but then is never reset back to "Y" if it *is* found.

Also, if you wanted to, you could change
      lFound = "Y"
      iLoopCtr = (GetXMLText("Required\Attempts")+1)

to just
      lFound = "Y"
      Exit For

Regards.

Rob.
0
 

Author Closing Comment

by:kkbenj
ID: 36712697
Thank you!
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question