?
Solved

CFileFind FindFile() function

Posted on 1998-04-03
1
Medium Priority
?
420 Views
Last Modified: 2012-05-04
How do I locate:
1.  A directory by name somewhere off the root, i.e. "C:\\*\*anywhere*\\DirectoryNameWIthUnknownLocation
2.  A specific filename in an unknown subdirectory, i.e. "FileWIthUnknownLocation.BIN"
with both searches starting at the root directory of a hard drive (not Internet)
0
Comment
Question by:CelebrationOfSpirit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 150 total points
ID: 1184046
You're going to have to use a recursive directory search that looks something like this:

char* MyFindFile(char* root, char* name, BOOL isDir)
{
  if (isDir)
  {
    dir = forEachDirInRoot(root)
    {
      if (Matches(dir, name))
        return root + dir;
      else
        return MyFindFile(root + dir, name, isDir);
    }
  }
  else
  {
    file = forEachFileInRoot(root);
    {
      if (Matches(file, name))
        return root + file;
    }
    // not in this dir
    //
    dir = forEachDirInRoot(root)
    {
      return MyFindFile(root + dir, name, isDir);
    }
  }
  return NULL;
}

Note that this is pseudocode, but it would be coded like that.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question