Jump to content
  • Advertisement
Sign in to follow this  
XTAL256

C/C++ Standard library "find file" function

This topic is 3695 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

I need a function that finds all files/folders within a given directory. I want to use a standard function so that i can port my game, so i don't want to use Windows' FindFirstFile and FindNextFile functions, but i can't find any such function in the C or C++ standard library. Can anyone help me? thanks

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by XTAL256
I need a function that finds all files/folders within a given directory. I want to use a standard function so that i can port my game, so i don't want to use Windows' FindFirstFile and FindNextFile functions, but i can't find any such function in the C or C++ standard library. Can anyone help me?
thanks


Pretty sure the standard library doesn't contain such functionality, but you might find boost.filesystem useful for this.

Share this post


Link to post
Share on other sites
Quote:
...but you might find boost.filesystem useful for this.
Yup, boost::filesystem is probably your best option here.

Share this post


Link to post
Share on other sites
Well i did download Boost a while ago but i can't be bothered installing it/setting it up, and i don't want to include it in my game just to use one function. If anything, i would rather use a small cross-platform library. Unless there is a way to do it using std lib, like using I/O to search a directory (?).

Share this post


Link to post
Share on other sites
The Posix standard has some C functions guaranteed to be on pretty much any modern OS. They're pretty ugly though.

Share this post


Link to post
Share on other sites
Quote:
Original post by Telastyn
The Posix standard has some C functions guaranteed to be on pretty much any modern OS. They're pretty ugly though.


He is referring to dirent.h, which is a POSIX API and Windows does not implement natively.

Though there are wrappers that make this API available on Windows. A couple come up if you google it.

Share this post


Link to post
Share on other sites
Quote:
Original post by fpsgamer
Quote:
Original post by Telastyn
The Posix standard has some C functions guaranteed to be on pretty much any modern OS. They're pretty ugly though.


He is referring to dirent.h, which is a POSIX API and Windows does not implement natively.

Though there are wrappers that make this API available on Windows. A couple come up if you google it.


Eh thank you. It's been ages since I've used that stuff; had forgotten the name.

Share this post


Link to post
Share on other sites
Quote:
Well i did download Boost a while ago but i can't be bothered installing it/setting it up, and i don't want to include it in my game just to use one function.
As far as installing Boost goes, on Windows it should be very easy: just use the installers from BoostPro. I believe there are pre-built binaries for Linux as well. I'm not sure about OS X, so you might have to build it there.

As for including it in your game, I'm going to venture a guess that the Filesystem library is not that big and won't add significantly to your executable's size (perhaps someone can confirm or deny this). Also, I wouldn't worry about including it 'just to use one function'. The functionality offered by the Filesystem library is very handy, and I'm willing to bet you'd find other places to use it.

In any case, it sounds like you're willing to incorporate some third-party code into your project, so it seems to me it might as well be Boost.Filesystem (which is tried and tested, and does exactly what you want).

Share this post


Link to post
Share on other sites
Ok, thanks i'll check it out. But for the moment i'll just write code for each OS and use #ifdef. i.e:

#if defined(_WIN32)
FindFirstFile(...)
#elif defined(_MAC)
// MacOS code for finding files
#endif


Something like that. And i can replace that when i use whatever library i end up using.

[Edited by - XTAL256 on June 29, 2008 8:30:50 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by XTAL256
Ok, thanks i'll check it out. But i think it would just be easier to write code for each OS and use #ifdef. i.e:
*** Source Snippet Removed ***
Something like that. After all, that's what most cross-platform libs do, right?


Neither of the options we presented require you to use OS specific macros. Either use the POSIX API on all platforms, or use the boost::filesystem API on all platforms.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!