July 11th, 2003, 04:45 AM
How to display a list of directories
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:
July 11th, 2003, 10:23 AM
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.
July 14th, 2003, 02:36 AM
I am using both gcc and the Command Line compiler for Visual Studio.
Does that help?
July 14th, 2003, 09:58 AM
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.
July 15th, 2003, 02:01 AM
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)?