Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

FileSystemObject.FileExist problems

85 views
Skip to first unread message

alan sinclair

unread,
Oct 16, 2001, 2:22:58 PM10/16/01
to
Hi

On our build system a script call to FileSystemObject.FileExists frequently
fails. I suspect the environment is being messed up somehow by the build
but don't know what to look for. Any ideas?

The failing script fragment is

Dim BNFile : BNFile = "d:\proj\build_number.txt"
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
If Not (fso.FileExists(BNFile)) Then Fail "Cannot find file " & BNFile

the file DOES exist, so what might stop FileExists from finding it?
Other scripting functions (e.g. WScript.ScriptName and
WshShell.ExpandEnvironmentStrings) work ok.

thanks for any suggestions -- i'm a beginner at VBS
Alan


Torgeir Bakken

unread,
Oct 16, 2001, 3:40:58 PM10/16/01
to
Hi Alan

Have you jumped on the scripting bandwagon and left msi ;-)

A very odd situation you have here, I think.

What is the environment you are running the script from?
Is the file locked/opened by another application during your test?

What are you planning to do with the file if it exists? Read from it, write to
it or what? If you are going to open it for reading\writing, you could try to
trap the error instead to detect if it exists or not.


Regards,
Torgeir

alan sinclair

unread,
Oct 16, 2001, 4:48:16 PM10/16/01
to
Hi Torgeir, thanks for the interest :-)

> Have you jumped on the scripting bandwagon and left msi ;-)

no, still MSIing -- just trying a little scripting to store our build number
into the msi database

> What is the environment you are running the script from?
> Is the file locked/opened by another application during your test?

Running under W2K pro sp1,
Opening a read-only text file to read the build number (file has single line
of text of form "1234").
The file isn't locked -- it's updated by a perl script as the build process
starts, then just sits there.
I added the FileExists check because the OpenFile was failing in the same
random way.
If FileExists discovers the file is missing, then it's recovered from source
control:

If Not (fso.FileExists(BNFile)) Then
WshShell.Run "p4 sync -f //depot/build_number.txt" : CheckError ' P4 =
perforce sccs


If Not (fso.FileExists(BNFile)) Then Fail "Cannot find file " & BNFile

End If

the P4 command may also be failing -- perforce doesn't log 'sync' commands
so I can't be sure (CheckError finds none here) -- but , the Fail "Cannot
find file" error path is taken even though the file IS present (checking
manually after the build completes)

If i run the script manually from the command prompt, it always works, even
after it has just failed during a build.
Running under Nmake, our build system does odd stuff (fires up extra Cmd
boxes with specialized environments for building device drivers), so it
seems the build must mess something up ... how can i find out what? The
confusing part is that it works in the build script 20% of the time. Our
build procedure always heavy-handedly deletes and refreshes the entire
source tree for consistency, and sets the environment every time, so
theoretically(!) there should be no variation between builds.

alan

Torgeir Bakken

unread,
Oct 16, 2001, 7:07:25 PM10/16/01
to
Hi

A couple of thoughts on your problem:

WshShell.Run "p4 sync -f //depot/build_number.txt" : CheckError

The way you run it here, VBScript will *not* wait for the completion of p4
before continuing. CheckError will run in parallel with p4.

To make it wait, you must do like this (it's the "True" that is important):

WshShell.Run "p4 sync -f //depot/build_number.txt", 1, True : CheckError

If you have more .Run statements without ", True" before this one, can this be
the culprit for your problem with the existing non-existing file?


If not, could you try to add the start of this bat file from your VBScript and
report back the result here on the c:\_log.txt-file in a case where the
fso.FileExists fails?

del c:\_log.txt
if exist d:\proj\build_number.txt echo file found >c:\_log.txt
pause

like this:
WshShell.Run "%comspec% <path\name.bat>", 1, True

alan sinclair

unread,
Oct 16, 2001, 7:30:39 PM10/16/01
to
Torgeir -- many thanks, you fingered the problem.

The missing "Wait" was leading to timing problems, and adding the wait fixed
it. Because the build_number file existed when I looked, I'd wrongly
assumed it was always there, but it wasn't and perforce didn't always
provide it in time.

Your help is much appreciated :-)
Alan

"Torgeir Bakken" <Torgeir.B...@hydro.com> wrote in message
news:3BCCBDAD...@hydro.com...

0 new messages