cplusplus.com
C++ : Forum : UNIX/Linux Programming : Reading a whole folder
 
cplusplus.com
Information
Documentation
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs


post Reading a whole folder

marlinde17 (16)
Hi,
I am currently working on a program that reads numerical data from a file and analyzes it (searches for a maximum, etc.). Is there a way I can input the name of a whole folder and have the program open, analyze, and close all files in that folder? Any input is greatly appreciated.
Thanks
Duoas (5974)
There are a lot of ways to do it. I suggest you start here:
http://linux.die.net/man/3/opendir

Be sure to look through the links at the bottom of the page.

opendir() +readdir()/scandir() +closedir() are for reading the directory's contents something like you would read a normal file.

glob() is to get a list of files that match a pattern (like "foo/*.c")

getdirentries() is a common but non-POSIX function that returns a list of filenames.

ftw() provides a nice abstraction over the fts_x() functions to call a function that you provide once for each directory entry.

Hope this helps.
Topic archived. No new replies allowed.