Strange Issue with FileExist

Started by keslaa, June 30, 2016, 08:45:20 AM

Previous topic - Next topic

keslaa

I am trying to build a script to install some programs. After the installer completes, I verify the existence of certain files before continuing on. The code:

App = "FlashPlayer ActiveX"
AppLocation = "C:\Windows\System32\Macromed\Flash\"
AppCheckFile = "%AppLocation%Flash64_22_0_0_192.ocx"

If FileExist(AppCheckFile ) == @TRUE
message("","%App% Found")
else
message("","%App% NOT Found")
endif


Pretty straightforward and I've used this technique many, many times before. Now, all runs of this code come back with NOT Found even though the file is there. I tried changing to the directory and calling the name directly. I even tried itemizing the files, selecting from an ASKITEMLIST command and still nothing. What am I missing?

td

If you review the help file documentation for FileExist you will notice that:

"(i) @TRUE (1) if the file exists; @FALSE (0) if it doesn't exist or if the pathname is invalid.; (2) if the specified file exists but is currently open by another application in read deny mode."

and there are other reason why a file could be 'unreadable' but the above is a good first possibility.

The upshot is that  if you test for '@True' and the function returns 2, your test will fail because the value of '@True' is 1.  It is better to simply test for a non-zero return:
Code (winbatch) Select
App = "FlashPlayer ActiveX"
AppLocation = "C:\Windows\System32\Macromed\Flash\"
AppCheckFile = "%AppLocation%Flash64_22_0_0_192.ocx"

If FileExist(AppCheckFile )                   ; <----------------------------------------------------
   message("","%App% Found")
else
   message("","%App% NOT Found")
endif




"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

keslaa

Thank you for the reply. I think I found the issue, but still can't explain it.

When your suggestion didn't work, I modified the code using FileItemize to create a list of files within the AppLocation and then, by going one-by-one through the list, compared the extracted name with the one I was looking for using a message statement. I discovered that even though I explicitly used "C:\Windows\System32\Macromed\Flash\" as my search folder, the code instead returned the contents of "C:\Windows\SysWOW64\Macromed\Flash". How does this happen when I am explicit in my definition?

td

My bad.  I failed to notice that you were referencing the 'system32' directory.  You have encountered file redirection.   To work around this problem you need to either user 64-bit WinBatch or use one of the techniques mentioned in the following Tech Database article:

http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/64-bit+File~Redirection.txt
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

keslaa

And that was it. I will disable the file redirection for this section of the code. Thank you!