Boost logo

Boost :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2005-09-28 06:31:23


John Maddock wrote:
> > It seems that testing for a path "J:/foo/bar" on a Win98 or Win2000
> > machine (unsure which ATM) that doesn't have a J: drive is returning
> > true falsely here because you ain't catching the correct error. Now,
> > I have to say I
> > don't agree with this policy of JM's, but suspect that the actual
> > error is ERROR_INVALID_DRIVE. Will get back to you when my testers
> > get back to me.
>
>I'm not sure I agree with that policy either: that's why there's a comment
>in the code that it may not be correct. The basic problem is we don't know
>which error codes represent "file does not exist", as opposed to some other
>error. The fact there is no documentation on which error codes that API
>can
>return makes the problem particularly tricky :-(

I agree that it could potentially return any error code, but according to
the Windows documentation, the correct way of dealing with errors is to say:

   if( !SomeAPIThatMayFail( ... ))
   {
      DWORD error = GetLastError();
      // Process error based on values from winerror.h
   }

winerror.h defines:

ERROR_FILE_NOT_FOUND // "The system cannot find the file specified."
ERROR_PATH_NOT_FOUND // "The system cannot find the path specified."
ERROR_FILE_EXISTS // "The file exists."
ERROR_POTENTIAL_FILE_FOUND // "A file was found, but it may not be the
correct file."

I think these are the main ones relating to file/path existence. Note that
ERROR_FILE_EXISTS will be returned by things like CopyFile when attemping to
copy to a file that already exists and you haven't specified to overwrite
that file.

- Reece


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk