Solved

Directory search routine

Posted on 1998-05-27
13
242 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

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