Sign in to follow this  
martin_bfg10k

Opening directories and get files (C++)

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this