Archived

This topic is now archived and is closed to further replies.

doctorsixstring

File searching

Recommended Posts

Is there any particular function that will search an entire drive for a particular file? I have been studying FindFirstFile() and FindNextFile(), but it seems like it would be quite laborious to use those functions to search the entire hard drive. Is there another, simple function to do this? I'm using Visual C++ 6.0 w/ the Win32 API. Thanks, Mike [edited by - doctorsixstring on April 29, 2002 4:56:25 PM]

Share this post


Link to post
Share on other sites
Why would it be laborious? Can''t you just use that function in a for loop and compare if the filename to what you''ve found?

I haven''t used that function before though.

Share this post


Link to post
Share on other sites
recursion is the simplfication you are missing. you search through all the files (directories are files too) in the root directory first. then each time you hit a directory, you call your search function again with the new path (ie ./newdirectory). you continually do this and eventually you will go through all the files.

Share this post


Link to post
Share on other sites
Pseudo-code:

function findFile(string name, string directoryName)
{
enumeration e = getDirectoryContents(directoryName);
for(item i in e)
{
if(i.name is name)
{
print("found it in " + directory);
break;
}
if(i.type is directory)
{
findFile(name, directoryName + i.name);
}
}
}

Share this post


Link to post
Share on other sites