Solved

File Searching

Posted on 1998-03-11
7
189 Views
Last Modified: 2010-05-18
VC5.0:
How do i search and retrieve the path of a file  TEST.CPP ?  The drive and the directory which it sits in is unknown.


 
0
Comment
Question by:engllf
  • 3
  • 2
  • 2
7 Comments
 

Author Comment

by:engllf
Comment Utility
Edited text of question
0
 

Expert Comment

by:mpewjg
Comment Utility
Please try class CFileFind

FindFile() can begin the search.
GetFilePath() can fetch the found file's path name.
0
 

Expert Comment

by:mpewjg
Comment Utility
CFileFind is an MFC class.  Are you working in MFC?
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 22

Expert Comment

by:nietod
Comment Utility
Prefer direct call to API.
0
 

Author Comment

by:engllf
Comment Utility
I am working in MSVC.
But I prefer direct call to API.
I am trying not to rely to much on MFC.  

0
 

Author Comment

by:engllf
Comment Utility
answer coming in a minute.
0
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
Comment Utility
First you need a starting point for your search, possibly the root directory of a specified drive, or some other directory depending on you needs.  You will search that directory and if you find the file you are done.  If not you will find each sub-directory in the directory and search them recursively until one search succeeds.  

To search a directory for a file or for other directories use the FindFirstFile() and FindNextFile() API commands (there are also extended versions, that might be a little faster.)  

for a particular directory use FindFirstFile() to get information about the file and then enter a loop that checks the information to see if it is a the right file.  If it is, return true from your search procedure.  If not, use FindNextFile() and continue the loop until you find the file or FindNextFile(0 fails (the FindFirstFile() could also fail) indicating there are no more files.  In that run a second loop that is like the first but this time check the attributes of the files found to see which one are directories.  If a file is a directory call the search function recursively.  If it returns true, return true. If it returns false, continue the loop.  When this loop runs out of files, return false, indicating the file was not found in the directory or its sub-directories.

let me know if you need any details.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 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.

763 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

14 Experts available now in Live!

Get 1:1 Help Now