#include <dirent.h> void traverse(const char *dir_name) { struct dirent *ent = NULL; DIR *p_dir = NULL; p_dir = opendir(dir_name); if (NULL != p_dir) { while (NULL != (ent = readdir(p_dir))) { char found[MAX_STR_LEN]; memset(found, 0, MAX_STR_LEN * sizeof(char)); sprintf(found, "%s/%s", dir_name, ent->d_name); if (ent->d_type == 8) { // to something with file } else if (0 != strcmp(ent->d_name, ".") && 0 != strcmp(ent->d_name, "..")) { // to something with sub-dir } } } }