列出文件夹全部文件 代码(C)
本文地址:http://blog.csdn.net/caroline_wendy
首先配置环境,參考:http://blog.csdn.net/caroline_wendy/article/details/39743345
输出文件夹中的全部文件名称
代码:
/*By C.L.Wang * Eclipse CDT * Ubuntu 12.04 * 2014.10.5*/#include "apue.h"#include "error.h"#include參数:int main(int argc, char* argv[]) { DIR *dp; struct dirent *dirp; if (argc != 2) err_quit("usage: ls directory_name"); if ((dp = opendir(argv[1])) == NULL) err_sys("can't open %s", argv[1]); while ((dirp = readdir(dp)) != NULL) printf("%s\n", dirp->d_name); return 0;}
/dev输出:
...logfb0dvdrwdvdcdrwcdromv4lvcsa6vcs6vcsa4(others)