Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we check if a file Exists or not using Win32 program?

How can we check if a file Exists or not using a Win32 program? I am working for a Windows Mobile App.

like image 1000
RK- Avatar asked Sep 30 '10 08:09

RK-


People also ask

Which method is used to determine if a file exists?

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.

How do you check if a file exists in C++ Windows?

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.


2 Answers

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?

like image 196
Zach Burlingame Avatar answered Sep 19 '22 23:09

Zach Burlingame


You can make use of the function GetFileAttributes. It returns 0xFFFFFFFF if the file does not exist.

like image 21
codaddict Avatar answered Sep 17 '22 23:09

codaddict