file/ls1.c
1 #include "apue.h" 2 #include <dirent.h> 3 int 4 main(int argc, char *argv[]) 5 { 6 DIR *dp; 7 struct dirent *dirp; 8 if (argc != 2) 9 err_quit("usage: ls directory_name"); 10 if ((dp = opendir(argv[1])) == NULL) 11 err_sys("can‘t open %s", argv[1]); 12 while ((dirp = readdir(dp)) != NULL) 13 printf("%s\n", dirp->d_name); 14 closedir(dp); 15 exit(0); 16 }
列出一个目录中的所有文件
时间: 2024-10-05 09:50:17