Solved

CFileFind FindFile() function

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 clear a vector as well as how to detect empty vectors in C++.

776 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