Jump to content
  • Advertisement
Sign in to follow this  
martin_bfg10k

Opening directories and get files (C++)

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

Maybe this is a stupid question, but I still don't know how to do this :O How can I open directories and get what and how files are in there. Is there some function like those old findfirst() and findnext() for get files from a directory? It must be a portable, because I code in windows and Linux. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Uh oh!

To do anything advanced with file structures (getting properties of directories and files, changing permissions, etc), you'll be needing OS-dependant code. In windows it's currently Win32 (still), however I believe that that will change with Vista (confirmation anyone?). Under Linux... I'm not really sure. You're going to have to either find an existing library out there, or write all the code twice, and cover half with #ifdefs, depending on the OS you're compiling for at the time.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
In Linux you'll want to look at the opendir(), readdir(), and closedir() functions in sys/types.h or dirent.h.

Other useful ones are chdir(), getcwd(), and mkdir().

Hope that helps.

It's all pretty simple to code and work with, so don't fret if you have to write it differently for Windows.

Share this post


Link to post
Share on other sites
Dang, there is a boost::something for almost everything.
When do they finally have boost::WriteMyProgram?
Simply impressive.

Share this post


Link to post
Share on other sites
Ohhhh! That's what I needed. I never used boost because I didn't wanted to much lib dependecies in my program, but it seems that I'll use now.
Thanks a lot.

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!