Solved

Directory search routine

Posted on 1998-05-27
13
246 Views
Last Modified: 2010-04-02
I'm looking for a fast disk directory search routine in C or C++.   This code will be part of a post login script that will allow us to perform a software inventory across our network (8000+ users) and I'd like to make it as transparent as possible to our users.  It will need to be able to detect multiple local drives to search and then search for all filenames given in a text file.
0
Comment
Question by:MitchelG
[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
  • 5
  • 5
  • 3
13 Comments
 
LVL 11

Expert Comment

by:mikeblas
ID: 1164852

Get NJFIND16.ZIP from http://www.nwlink.com/~mikeblas/samples/. I wrote it almost 10 years ago: it is 16-bit DOS app that works on DOS 3.x, 4.x, 5.x, and 6.x, and is compatible with more than half a dozen archive file formats (like ZIP, ARC, and LZH).

.B ekiM

0
 
LVL 11

Expert Comment

by:alexo
ID: 1164853
What is the platform it will fun on?  DOS?  Win9x/NT?  Unix?
Would you like to detect and search only local drives or networked too?
Would you like a tool or source code?
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1164854
Have you already received an answer?

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:MitchelG
ID: 1164855
mikeblas,

  I can't get this to work it seems to be making DOS calls to, I think, find out what drive types are on the system.  It appears to be dieing at that point.  I would love more assistance.  I'm also working with alexo on this and would really like to grade your work, but I'm not sure the best way to do it, as I'm sure the code is great, I just can't get it to work for me.  Can I get your EMail address somewhere so we can resolve this quickly and you can get your points.

  Unfortunately for me this is just one piece of a much bigger project and I'm in a bit of a rush.  I definetly don't want to sound rude or demanding, I just wanted you to know that it's a hot item on my plate and I'd sure love to put this piece behind me.

  Thanks in advance for your time, patience, and expertise,
 
       Mitch
0
 
LVL 11

Expert Comment

by:alexo
ID: 1164856
Don't wait for me.
0
 

Author Comment

by:MitchelG
ID: 1164857
I've re-opened this hoping someone has a soultion using only C or C++ and no assemler, perhaps a recursive findfirst/findnext routine.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1164858
Mithel, recursive findfirst/findnext is the least of your problems because it is fairly trivial.
What you need is a method to determine whether a drive is local, remote, floppy or nonexistant.
0
 

Author Comment

by:MitchelG
ID: 1164859
Alex, I'm not disagreeing but at this point I need something finding files on at leaset C drives (Luckily, our H/W configurations are 'fairly' fixed, nearly all machines have only one floppy [the A drive] and few have more than two hard drives, none can have local drive letters above G and most have one CD), I can add the Local/Network/CD file detection later.  Nonexistant drives shouldn't present a problem as even findfirst returns an error code so if that's checked for on the root directory of any drive, that's handled).  So, although it is the least of my troubles, it is still one of my troubles and I'd like a routine that works that will help me out with it.
0
 
LVL 11

Accepted Solution

by:
alexo earned 200 total points
ID: 1164860
Compiled as a DOS application with BC5.02 and tested on an NT machine:

    #include <dos.h>
    #include <dir.h>
    #include <string.h>

    #define ANY_ATTRIBUTE   (_A_RDONLY | _A_HIDDEN | _A_SYSTEM)
    #define ALL_FILES       "\\*.*"

    int RecursiveFind(const char* dir, const char* filename)
    {
        char            path[MAXPATH];
        struct find_t   result;
        int             len;
        int             done;

        memcpy(path, dir, len = strlen(dir));
        if (path[len - 1] == '\\')
            --len;

        strcpy(path + len, ALL_FILES);
        done = _dos_findfirst(path, _A_SUBDIR, &result);
        while (!done)
        {
            if (result.attrib == _A_SUBDIR && *result.name != '.')
            {
                strcpy(path + len + 1, result.name);
                if (RecursiveFind(path, filename))
                    return 1;
            }
            done = _dos_findnext(&result);
        }

        strcpy(path + len + 1, filename);
        return !_dos_findfirst(path, ANY_ATTRIBUTE, &result);
    }

    /* Tester */
    void main()
    {
        return RecursiveFind("C:\\", "mode.exe");
    }

0
 

Author Comment

by:MitchelG
ID: 1164861
Works great thanks
0
 
LVL 11

Expert Comment

by:alexo
ID: 1164862
Have Fun!
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1164863
My code works fine for DOS.  Did you mean to mention in your original question that you were working on a specific operating system?

B ekiM
0
 

Author Comment

by:MitchelG
ID: 1164864
Mike,

  Perhaps, I wasn't specific enough.  I could not get it to run under Win95 in a DOS window.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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 how to clear a vector as well as how to detect empty vectors in C++.

696 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