How can we check if a file Exists or not using a Win32 program? I am working for a Windows Mobile App.
path. exists() function to check if a file exists. To check if a file exists, you pass the file path to the exists() function from the os. path standard library.
The FileExists Method (System::SysUtils::FileExists) is a SysUtils Method in C++ Builder that checks whether a specified file exists. FileExists returns True if the file specified by FileName exists. If the file does not exist, FileExists returns False.
Use GetFileAttributes
to check that the file system object exists and that it is not a directory.
BOOL FileExists(LPCTSTR szPath) { DWORD dwAttrib = GetFileAttributes(szPath); return (dwAttrib != INVALID_FILE_ATTRIBUTES && !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); }
Copied from How do you check if a directory exists on Windows in C?
You can make use of the function GetFileAttributes
. It returns 0xFFFFFFFF
if the file does not exist.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With