Solved

Directory search routine

Posted on 1998-05-27
13
240 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MSVCR80.dll crash 2 134
SetCurrentDirectory path limit 7 104
c++ reading data from file into two dimensional array 3 95
trigs fail! I thought I knew how to do trignometry 3 55
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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.

911 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

20 Experts available now in Live!

Get 1:1 Help Now