How to check if file exists using C program ?
If we want to see whether certain file exists or not before doing some operation like read/write etc, then C provides an API called “access”. access() checks whether the calling process can access the file pathname.
To check if a file is present or not, we need to use mode as “F_OK”.
The below program, passes an argument of filename with absolute path, OR check a default file “adb” is present or not.
result = access (filename, F_OK); // F_OK tests existence also (R_OK,W_OK,X_OK).