#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    Scotland
    Posts
    185
    Rep Power
    12

    How to display a list of directories


    Hi all,

    I am messing about with a small menu program.

    I would like to run a command on a PC, but I would also like to have some way of showing all direcotories on a hard drive and allowing the user to select from which directory the command will be run.

    I am using stanard C, not Visual C++

    Anyone got any suggestions?:confused:
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,255
    Rep Power
    2222
    But what C compiler are you using? Because we're getting into system-dependent programming here, which isn't always standard.

    In UNIX/Linux and hence also in the DOS ports of gcc, you would use the functions opendir, readdir, and lstat (or stat) in order to read through the directories and determine which files are themselves directories. I found opendir and readdir in Borland's Turbo C++ v3, but not stat nor lstat. In VC++ 1.52, I found stat, but not lstat nor opendir nor readdir.

    So what compiler are you using? And check the help for references to the functions I mentioned.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    Scotland
    Posts
    185
    Rep Power
    12
    I am using both gcc and the Command Line compiler for Visual Studio.

    Does that help?
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,255
    Rep Power
    2222
    Originally posted by Jadams
    I am using both gcc and the Command Line compiler for Visual Studio.

    Does that help?
    Together? Does that work?

    I also use both, but separately. gcc will use the opendir, readdir, closedir, and lstat (or stat -- it's been a while) functions. One problem I encountered with my MinGW gcc port was that the directory functions required the libmingw32.a library (as I recall) to be linked in, but I had a terrible time figuring out that that was the required library. At least it comes with a copy of the nm utility.

    As for VC++6, it supports the _findfirst and _findnext functions that grew out of the DOS service calls by the same name. Basically, you call _findfirst with the wildcard spec and it returns the first match, then you repeatedly call _findnext and it each time returns the next match, until there are no more matches. Either function returns an error if there are no [more] matches.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    Scotland
    Posts
    185
    Rep Power
    12
    I meant separatly.

    I was hoping (silly I know) that there was some common way of directory access accross all platforms.

    If I am using Windows and the VC++ compiler, how can I open a directory? Use System(cd C:\blah)?

IMN logo majestic logo threadwatch logo seochat tools logo