Re: How do you use FindFirstFile ?
- From: Timothy Madden <terminatorul@xxxxxxxxx>
- Date: Wed, 20 Jul 2005 10:49:36 +0300
William DePalo [MVP VC++] wrote:
Take this quick hack:
#include <windows.h> #include <iostream>
DWORD DoesFileExist(LPCSTR pszName) { char szMsg[256]; DWORD dwStatus;
if ( GetFileAttributes(pszName) != INVALID_FILE_ATTRIBUTES ) dwStatus = ERROR_SUCCESS;
else dwStatus = GetLastError();
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, dwStatus, 0, szMsg, sizeof(szMsg), 0);
std::cout << pszName << " : " << szMsg;
return dwStatus; }
int main() { DoesFileExist("<>"); DoesFileExist("a.b"); DoesFileExist("c:\\windows\\notepad.exe");
return 0; }
It prints
<> : The filename, directory name, or volume label syntax is incorrect. a.b : The system cannot find the file specified. c:\windows\notepad.exe : The operation completed successfully.
on this XP/Pro/SP2 box.
If I do so then I have to print a message when the file does not exist.
For my app it is correct and valid for the file not to exist. I have nothing meaningful to print in this case. I only have to set a flag to ask some library to create the file later if I will need to.
"Timothy Madden" Romania .
- Follow-Ups:
- Re: How do you use FindFirstFile ?
- From: William DePalo [MVP VC++]
- Re: How do you use FindFirstFile ?
- References:
- How do you use FindFirstFile ?
- From: Timothy Madden
- Re: How do you use FindFirstFile ?
- From: William DePalo [MVP VC++]
- Re: How do you use FindFirstFile ?
- From: Timothy Madden
- Re: How do you use FindFirstFile ?
- From: William DePalo [MVP VC++]
- How do you use FindFirstFile ?
- Prev by Date: Re: bug in visual studio .net 2003 - breakpoints and memcpy
- Next by Date: Re: How do you use FindFirstFile ?
- Previous by thread: Re: How do you use FindFirstFile ?
- Next by thread: Re: How do you use FindFirstFile ?
- Index(es):
Relevant Pages
|