Created
July 3, 2014 13:26
-
-
Save yaraki/54c505b8607ac8b42f5b to your computer and use it in GitHub Desktop.
Lists up all the subdirectories in the current directory recursively.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <dirent.h> | |
void list(const char *path) | |
{ | |
DIR *dir; | |
struct dirent *entry; | |
char entry_path[PATH_MAX]; | |
char *entry_name = entry_path; | |
dir = opendir(path); | |
if (NULL == dir) { | |
return; | |
} | |
while ((*entry_name++ = *path++)) | |
; | |
--entry_name; | |
*entry_name++ = '/'; | |
while (NULL != (entry = readdir(dir))) { | |
if ('.' == *(entry->d_name)) { | |
continue; | |
} | |
if (DT_DIR == entry->d_type) { | |
strcpy(entry_name, entry->d_name); | |
puts(entry_path); | |
list(entry_path); | |
} | |
} | |
closedir(dir); | |
} | |
int main () | |
{ | |
list("."); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use [F2] to change directory using peco