Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CFileFind FindFile() function

Posted on 1998-04-03
1
Medium Priority
?
428 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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

618 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