Solved

Directory search routine

Posted on 1998-05-27
13
239 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
  • 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

707 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

17 Experts available now in Live!

Get 1:1 Help Now