Solved

CFileFind FindFile() function

Posted on 1998-04-03
1
410 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 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unable to start eclipse ? 17 163
Precision Problem in C++ 7 52
One named event, multiple event handlers 2 45
C++ statement T∗ begin(Vector<T>& x) 5 12
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

730 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