Created
February 12, 2012 06:41
-
-
Save xiaom/1806808 to your computer and use it in GitHub Desktop.
check if a file exists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <unistd.h> | |
// Check whether file exist | |
// http://stackoverflow.com/questions/230062/whats-the-best-way-to-check-if-a-file-exists-in-c-cross-platform | |
if( access( fname, F_OK ) != -1 ) { | |
// file exists | |
} else { | |
// file doesn't exist | |
} | |
/* | |
You can also use R_OK, W_OK, and X_OK in place of F_OK to check for read permission, write permission, and execute permission (respectively) rather than existence, and you can OR any of them together (i.e. check for both read and write permission using R_OK|W_OK) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment