Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _GNU_SOURCE
- #include <unistd.h>
- #include <sys/types.h>
- #include <dirent.h>
- #include <stdio.h>
- #include <string.h>
- http://www.cplusplus.com/forum/general/85870/
- void listdir(const char *name, int indent)
- {
- DIR *dir;
- struct dirent *entry;
- if (!(dir = opendir(name)))
- return;
- while ((entry = readdir(dir)) != NULL) {
- if (entry->d_type == DT_DIR) {
- char path[1024];
- if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
- continue;
- snprintf(path, sizeof(path), "%s/%s", name, entry->d_name);
- printf("%*s[%s]\n", indent, "", entry->d_name);
- listdir(path, indent + 2);
- } else {
- printf("%*s- %s\n", indent, "", entry->d_name);
- }
- }
- closedir(dir);
- }
- int main(void) {
- listdir("/home/filip/Desktop/root", 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement