How to find out if a file exists
| Nate879 (22) | |||
| How do I find out if a file exists? | |||
| Zaita (1175) | |||
| Please be more specific with your question. What operating system? Compiler? etc. | |||
| Nate879 (22) | |||
| There should be a portable way to do this, that wouldn't depend on OS, compiler, etc. If there isn't, I am using Windows XP + MinGW. | |||
| ropez (312) | |||||
Typically you only check if the file exists when you want to read from it:
I think if you only need to check if the file exists, the most portable way is to test if you can open it:
The return statement should cast the file object to a boolean which is true if the file exists. The file is automatically closed at the end of the function scope. | |||||
This topic is archived - New replies not allowed.
