Click to See Complete Forum and Search --> : FindFirstFile() question


C++ Newbie
January 27th, 2003, 09:49 AM
Hi, I've been trying to use the FindFirstFile function for reading files from a given input directory. basically, at the command line I write:

ProcessTextFiles "c:\data\*.txt"

so that I pass in the directory string as shown above. Now, when I run the code snippet below, it seems to correctly go the directory I want and step through the .txt files one at a time but in the returned structure

WIN32_FIND_DATA fileData;

I can see that you can retrieve the current filename (i.e., with cFileName method) but only without the path. How can I used FindFirstFile in a way where I can get the entire path:

for example:
"c:data\gg1.txt"
vs just
"gg1.txt"
??

Thanks!



if ((hFileRead = FindFirstFile(argv[1], &fileData)) != INVALID_HANDLE_VALUE){
do{
string FilenameWithFullPath = fileData.cFileName;
//Process this next text file
BuildDictionary.ProcessTextFile(FilenameWithFullPath);
}while (FindNextFile(hFileRead, &fileData));
}

RobAnd
January 27th, 2003, 11:11 AM
The truth is you cannot. You are responsible for appending on a path to the file. That is the way the API was designed.

Besides, you know what the path is. You passed it in yourself. Just parse the string if you need it and append it to each filename you need.

- Robert

C++ Newbie
January 27th, 2003, 11:42 AM
OK thanks. I was going to do that but thought that I must have missed something in the API and didn't want to reinvent the wheel.