Hello Noorez and all Dev-C++ users,
Monday, June 21, 2004, 5:24:58 AM, Noorez wrote as follows:
NK> My program creates files and the names are what ever the user says. How can
NK> I test to see if a file already exists?
Duh, sample from Platform SDK:
HANDLE hFile;
char *szFileName;//this is the file name you want to check
...
...
BOOL bFileExists = TRUE;
hFile = CreateFile(szFileName, // open some file
GENERIC_READ, // open for reading
FILE_SHARE_READ, // share for reading
NULL, // no security
OPEN_EXISTING, // existing file only
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template
if( hFile == INVALID_HANDLE_VALUE )
{
if( GetLastError( ) == ERROR_FILE_NOT_FOUND )
bFileExists = FALSE;
//in case of other errors file exists but it couldn't be opened for some
reason, you can check for more system error codes
}
else
CloseHandle( hFile );
--
regards, Zodiaq
|