// Programming 1. Sample at 2017-04-06-13-41.05 #include <stdio.h> #include <sys/types.h> #include <dirent.h> #include <string.h> void list_dir(const char *startdir) { char current_path[10000]; strcpy(current_path,startdir); DIR *dir = opendir(current_path); struct dirent *de = readdir(dir); if(dir) while(de) { printf("[%s/%s] %d\n",current_path,de->d_name,de->d_type); if( de->d_type == DT_DIR && 0!=strcmp(".",de->d_name) && 0!=strcmp("..",de->d_name)) { int path_len = strlen(current_path); strcat(current_path,"/"); strcat(current_path,de->d_name); list_dir(current_path); current_path[path_len] = '\0'; } de = readdir(dir); } closedir(dir); } int main(int c, char **v, char **env ) { for(int i=0;i<c;++i) printf("->%s\n",v[i]); for(int i=0;i<1000 && env[i]!=NULL; i++) printf("%s\n",env[i]); if(c==2) { list_dir(v[1]); } else { list_dir("."); } return 0; }