Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Directory search routine

Posted on 1998-05-27
13
Medium Priority
?
250 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 800 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

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…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

610 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