We help IT Professionals succeed at work.

File Search Algorithm

mrquija
mrquija asked
on
275 Views
Last Modified: 2010-04-02
Does anyone have a file Search algorithm I could use?  Example, I want to find mspaint.exe....I want to write a piece of code that would search for that file.  Thanks in advance.
Comment
Watch Question

Commented:
Under Win32 you call FindFirstFile/FindNextFile .. these return files that match a given spec and sttributes in a given directory.

Search a directory tree by making the function recursive (ie. look for your particular file and if not fount retrieve all directory names and call the search for each of those.)

In Win32 you can also find an executable that is registered by API calls .. but this may not be what you want.

Author

Commented:
I need a searching algorithm for DOS based, sorry.
Hello..
 You want the dos one right. U can do it in the following way..

 Have u used findfirst and findnext ..or ucan use dos interrupts..

 start from c:\(root) and search for the file also add the directory names in an array .Got it. When the current is finished take the last one from directory array ( remove it also) add it to current path and re perform search .If one has nothing inside it .just remove one upto a '\'and again add form array.It will work..

 Please note: it will search from the last one >not like dir /s which will starts from first one..

 Good luck.

Author

Commented:
haven't used those functions before.  Could you write code to implement?
moonlightSenior Technology Consultant
CERTIFIED EXPERT

Commented:
I will give you an algorithm, the functions are for unix,
use functions in the earlier answers for dos:
 for (dp = readdir(d); dp != NULL;dp = readdir (d) )
   {
   filename = dp -> d_name;
   if ( filename[0] == '.' ) continue ;
   cout << filename <<  "\n";
   }

this is only for your help, not an answer
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Im not sure if that code is going to compile either.  Seems too complicated for a file search algorithm?!?   But I'll give it a shot.  If anyone has anything SHORTER, it would be appreciated.

Commented:
The main reason for the length is the lengths (sic) you have to go to to set up a findfirst/findnext loop .. mostly the string manipulation.

You could used fixed size buffers to make it a bit simpler ,, as long as you make the buffers big enough.

The alrogithm itself is quite simply .. just the details get in the way.

Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.