#include #include #include #include #include #include #include char *current_path; void walk(char *path, int step) { DIR *dp = opendir(path); struct dirent *dirp; struct stat statbuf; while((dirp = readdir(dp)) != NULL) { if(!strcmp(dirp->d_name, ".") || !strcmp(dirp->d_name, "..")) continue; lstat(dirp->d_name, &statbuf); int i = 0; for(; i < step; i++) printf("\t"); printf("%s\n", dirp->d_name); if(dirp->d_type == 4) { char p[256] = ""; strcpy(p, path); if(step > 0) strcat(p, "/"); strcat(p, dirp->d_name); walk(p, step+1); } } } int main(int argc, char *argv[]) { if(argc > 1) current_path = argv[1]; else current_path = "./"; walk(current_path, 0); return 1; }