#define WIN32_LEAN_AND_MEAN
#include <iostream>
#include <windows.h>
int main()
{
WIN32_FIND_DATA FindFile;
HANDLE hFile;
if ( ( hFile = FindFirstFile( "C:\\TempHold\\*.txt",&FindFile ) ) ==
INVALID_HANDLE_VALUE )
{
std::cout << "Invalid File Handle." <<
std::endl;
exit( 0 );
}
do {
std::cout << FindFile.cFileName <<
std::endl;
} while ( FindNextFile( hFile,&FindFile ) );
return 0;
}
The code above uses the raw Win32 API to search for files in a particular directory. FindFirstFile() coupled with FindNextFile() will return all text files ( as denoted by the *.txt wildcard ) in the C:\TempHold folder on my disk. You can change this wildcard to a filename to search for that file in the folder. If that file is not in the directory in question, then "Invalid File Handle" will be displayed on the console. Mike L.G.
mlg400@blazemail.com