Opening directories and get files (C++)
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.
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.
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.
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.
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.
Boost::filesystem works on all platforms and makes it fairly easy to access files by iterating through a directory.
Bojan
Bojan
Dang, there is a boost::something for almost everything.
When do they finally have boost::WriteMyProgram?
Simply impressive.
When do they finally have boost::WriteMyProgram?
Simply impressive.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement