PDA

View Full Version : Going through a directory in C




farmerdoug
Sep 16, 2008, 01:09 PM
I want to perform the same set of operations on every file in a directory. How do I go through the files in a directory one at a time if I don't know the names or numbers of files in the directory? I know I can use system commands to make a list and then read the list one at a time but Microsoft C used to have routines that would take care of everything for you.



lee1210
Sep 16, 2008, 01:35 PM
readdir is probably what you are looking for.

Here is an example:
http://www.siit.tu.ac.th/mdailey/class/2003_s2/its225/assignments/readdir.c

You can also just 'man readdir' from the terminal.

-Lee

kainjow
Sep 16, 2008, 01:37 PM
Did you try using Google? The first result for "directories C" is:
http://code-jam.blogspot.com/2006/07/directories-in-c.html

farmerdoug
Sep 16, 2008, 01:39 PM
thanks