Skip to main content
gamedev.net
🔒 Locked

Subdirectory Reference in C

Started by Shadow Entertainment 3 replies 600+ views
Original Post
Shadow Entertainment
Shadow Entertainment
In C, I''m trying to find the function I''d need to call to return a list of all the subdirectories in a given directory, and one for a list of all the subfiles... preferably if it returned a char* array it would be great, but if you know of anything else, that''d be great too... anyone can help? also, could you give me the included header files you''d need to call the functions... thx
citizen3019
citizen3019
I know this is not exactly what you are looking for but:

//Change the current working directory.

int _chdir( const char *dirname );
int _wchdir( const wchar_t *dirname );

//Searches for a file using environment paths.

void _searchenv( const char *filename, const char *varname, char *pathname );
void _wsearchenv( const wchar_t *filename, const wchar_t *varname, wchar_t *pathname );

//Changes the current working drive.

int _chdrive( int drive );


...maybe these will help. C often lacks the all-encompassing functions available to us in C++, but when used in cunjunction with each other these functions can acheive the results you desire.

[edited by - citizen3019 on January 13, 2004 2:05:50 PM]
SiCrane
SiCrane
C has no standard functions for this. Any functions to do this would be compiler and/or operating system specific.
Null and Void
Null and Void
C''s standard library doesn''t know about directories (nor does C++''s), you have to use something higher level. POSIX and the Win32 API (among other things) provide their own directory handling functions (POSIX: opendir, readdir, closedir, et cetera; Win32: FindFirstFile, FindNextFile, et cetera). Certain C runtimes (MSVC''s) provide some functions that wrap the platform that they run on''s functions (findfirstfile and findnextfile, if I recall correctly).

Boost provides some C++ directory handling wrappers. For C, you should probably wrap the platform specific functions yourself unless you happen to already be using a higher level library that provides the same thing.

LessBread
LessBread
To add a little follow up to Null And Void''s comments, although many of the functions that he mentions appear to be file oriented, they also return information about subdirectories. Review their documentation with an eye towards that.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.