Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #180 List files in directory

Create the list x containing the contents of the directory d.

x may contain files and subfolders.
No recursive subfolder listing.

#include <dirent.h>
struct dirent ** x = NULL;
int n = scandir (p, &x, NULL, alphasort);

scandir allocates memory and returns the number of entries. each entry must be free'd. See also opendir, readdir and closedir and ftw for recursive traversal.

New implementation...
< >
programming-idioms.org