?
Solved

VBScript File Existence Check

Posted on 2011-09-21
3
Medium Priority
?
367 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

752 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