#include <stdio.h> #include <sys/types.h> #include <dirent.h> #include <errno.h> #include <string.h> void getdir(char *dirname) { DIR *MYDIR; struct dirent *diritem; if((MYDIR=opendir(dirname)) == NULL) perror("open dir error!/n"); while((diritem = readdir(MYDIR)) != NULL) { if((diritem->d_type == DT_DIR) && (strcmp(diritem->d_name, ".") != 0) && (strcmp(diritem->d_name, "..") != 0)) { // printf("%s is a directory!/n",diritem->d_name); printf("/nchange directory into %s:/n",diritem->d_name); getdir(diritem->d_name); } else { printf("%s/n",diritem->d_name); } } closedir(MYDIR); } int main(int argc, char* argv[]) { getdir(argv[1]); }