Is there any way to check if a file exists. I usually use a Mac, but for specific reasons I have to use Linux.
Is there any way to check if a file exists. I usually use a Mac, but for specific reasons I have to use Linux.
What's wrong with stat? (Which, after all, is how you'd it on a Mac anyway, right?)
dont think there's a function to check if a file exists. You could check if the directory exists but not a file. There are two way to achive this. You use either call stat() to find the file information or the function will returns 0, if the file doesn't exits. Or use fopen to check if the file exsists. Like
ssharishCode:int CheckFileExists( char *filename ) { FILE *fp; if( ( fp = fopen(filename,"r") ) != NULL ) { fclose( fp ); return 1; } return 0; }
Life is like riding a bicycle. To keep your balance you must keep moving - Einstein
Okay I am starting to check out stat. Fopen was causing a Segmentation fault on Ubuntu, so thats why I wanted help.
Edit: I can use some help with stat. I'm not that good with structs yet.
Last edited by Alegomaster; 01-21-2011 at 06:42 PM.