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
Solved

File Searching

Posted on 1998-03-11
7
192 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
ID: 1183378
Edited text of question
0
 

Expert Comment

by:mpewjg
ID: 1183379
Please try class CFileFind

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

Expert Comment

by:mpewjg
ID: 1183380
CFileFind is an MFC class.  Are you working in MFC?
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 22

Expert Comment

by:nietod
ID: 1183381
Prefer direct call to API.
0
 

Author Comment

by:engllf
ID: 1183382
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
ID: 1183383
answer coming in a minute.
0
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 1183384
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

828 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