Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <string.h>
- #include <dirent.h>
- #include <sys/types.h>
- void traverse(char *path, int indent)
- {
- DIR *dir = opendir(path);
- if (dir == NULL)
- {
- fprintf(stderr, "Eroare la deschiderea directorului.\n");
- exit(EXIT_FAILURE);
- }
- struct dirent *d;
- while ((d = readdir(dir)) != NULL)
- {
- if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
- continue;
- if (d->d_type == DT_DIR)
- {
- char buf[256];
- printf("%*s%s\n", indent, "", d->d_name);
- sprintf(buf, "%s/%s", path, d->d_name);
- traverse(buf, indent + 2);
- }
- else
- printf("%*s%s\n", indent, "", d->d_name);
- }
- }
- int main(int argc, char **argv)
- {
- if (argc != 2)
- {
- fprintf(stderr, "Syntax: %s <path>\n", argv[0]);
- exit(EXIT_FAILURE);
- }
- traverse(argv[1], 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement