+ Reply to Thread
Results 1 to 3 of 3

Thread: What is the best way to check file exists?

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    2

    What is the best way to check file exists?

    Hi,

    Can someone tell me what's the best way to check if file exists? Is GetFileAttributes the right one?

    Thanks!

  2. #2
    Junior Member
    Join Date
    Dec 2011
    Posts
    2
    I've been using the GetFileAttributes to check if file exists and it has worked just fine for me. Just make sure you also check GetLastError also. Here is an example:

    Code:
    bool FileExists(WCHAR *fname)
    {
      if(INVALID_FILE_ATTRIBUTES == GetFileAttributes(fname) && GetLastError()==ERROR_FILE_NOT_FOUND) 
         return false; //file not found 
      
      return true;  // file is found
    }

  3. #3
    Junior Member
    Join Date
    Dec 2011
    Posts
    1
    I also use GetFileAttributes. It's faster.

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts