Linux 下获取目录下的所有文件
#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <dirent.h>static int get_files(){DIR *dirp;struct dirent *dp;dirp = opendir(".");if ...
·
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <dirent.h>
static int get_files()
{
DIR *dirp;
struct dirent *dp;
dirp = opendir(".");
if (dirp == NULL) {
return -1;
}
while ((dp = readdir(dirp)) != NULL) {
printf("%s\n", dp->d_name);
}
(void) closedir(dirp);
return 0;
}
int main(int argc, char const *argv[])
{
get_files();
return 0;
}
更多推荐
已为社区贡献1条内容
所有评论(0)