views:

149

answers:

2

I am using the following to search for a file defined as a macro DB_CONFIG_FILE_PATH_1.

wchar_t filename[100];
SearchPath( L".\\", DB_CONFIG_FILE_PATH_1, NULL, 100, filename, NULL);

If the file is in C:\ directory, it is found. But, if the file is in one of its sub-directories the function doesn't find it.

Can some explain how to search all the drives including subdirectories for a file with the above function.

I am not using FindFirstFile function because, I am unable to retrieve the path to the file even though the function returns handle to the file.

To put it, I want full path name of a file. I know the name of the file, but do not know where it is on the comp.

A: 

For searching subdirectories in native code on Win32, you need to do it yourself, using FindFirstFile and then recursing into subdirectories.

The return value of FindFirstFile isn't a file handle - the file information is contained in the WIN32_FIND_DATA structure returned. The handle is used in calls to FindNextFile to continue the search. To get a full path name during your search, you'll need to keep track of what directory you are currently in and append the discovered directory names to the path.

SearchPath only searches in the PATH environment variable or the first parameter if present and doesn't search subdirectories.

Michael
A: 

GetCurrentDirectory() should tell you the path:

http://msdn.microsoft.com/en-us/library/aa364934(VS.85).aspx

and the second argument of FindFirstFile():

http://msdn.microsoft.com/en-us/library/aa364418(VS.85).aspx

which is a WIN32_FIND_DATA Structure should tell you the name of the file:

http://msdn.microsoft.com/en-us/library/aa365740(VS.85).aspx

Patrick Gryciuk