Solved

CFileFind FindFile() function

Posted on 1998-04-03
1
391 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
1 Comment
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 50 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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 viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now