Jump to content
  • Advertisement

Archived

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

doctorsixstring

File searching

This topic is 5955 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
How do you do to search recursively? Do you have a link for an example showing this way of searching a file in a HD?
Thanks in advance.

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!