--- In [email protected], Rick <[EMAIL PROTECTED]> wrote:
>
> Hi all,
> 
> How can I check to see if a file exists under the Windows OS?
> Something like:
> 
> if (!file_exists("c:\dir\file.ext"))
> {do_something}
> else
> {do_something_else}
> 
> What if the path is a directory?
> 
> if (!file_exists("c:\dir"))
> {do_something}
> else
> {do_something_else}

As far as I recall MS-DOS and Windows console programming, you will
have to use double backslashes within the file names, like this:
  if ( stat( "c:\\dir\\file.ext"))
  { /* not found */
  }
  else
  { /* Found! */
  }

In order to check whether a file names a directory, in earlier times I
have used this trick:
  if ( stat( "c:\\proposed_dir\\NUL"))
  { /* not a directory */
  }
  else
  { /* Is a directory */
  }
But I haven't tried this in ages.

Regards,
Nico

Reply via email to