When does FileExist() return 2?

Started by snowsnowsnow, October 03, 2014, 04:19:15 AM

Previous topic - Next topic

snowsnowsnow

AIUI, FileExist() is supposed to return 2 whenever a file is inaccessible because it is "in use".

But I have found a counter-example.

At the command prompt, I do: copy file.ext foofoo

and get err msg "The file cannot be copied because it is in use by ââ,¬Â¦" (whatever the exact wording is from the Command Prompt).

But when I do (in a WB script): Message("",FileExist("file.ext"))
it says 1.

But note that if I try to do the copy in WB:

FileCopy("file.ext","foofoo",1)

It just comes back with "FileCopy failed" (no further explanation).

The point of all this is that I had hoped that I could use FileExist() returning 2 to tell me that the FileCopy() will fail, but it seems not to be reliable.  It's not a real problem, since I can just error-trap the FileCopy() (I think; I haven't tested this yet, but I assume it will work), but it seems like the FileExist() ought to be returning 2.  Shouldn't it?


td

If the OS reports a read sharing violation error (32) then FileExist will return 2.  If the OS does not report a sharing violation then the function returns 0 or 1.  The MSFT provided text for this error simple states that it means that a file "is being used by another process."  Being used by another process is not the same thing as being locked by another process as the system has a different error for an attempt to access a file that is locked by another process. 

Newer versions of WinBatch have a More Error Info button on the error dialog that when enabled and clicked does exactly what the name suggests.  In the case of FileCopy, the additional error information is the error number of the system error generated when the file copy was attempted. 
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade


td

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