Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Shadow Entertainment

Subdirectory Reference in C

This topic is 5332 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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]

Share this post


Link to post
Share on other sites
C has no standard functions for this. Any functions to do this would be compiler and/or operating system specific.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!