#include <sys/types.h> #include <dirent.h> int main(int argc, char *argv) { DIR *dp; struct dirent *dirp; if(argc != 2) printf("输入格式:ls filename"); if( !(dp = opendir(argv[1])) ) printf("无法打开目录:%s", argv[1]); while( dirp = readdir(dp) ) printf("%s/n", dirp->d_name); closedir(dp); return 0; }