在linux和Mac中访问某个文件夹中所有的文件——输出所有的文件名
#include <stdio.h>
#include <dirent.h>
int main() {
struct dirent *
dirp;
DIR* dir = opendir(
"/Users/tanchao/Documents/wsy/切分错误");
while ((dirp = readdir(dir)) !=
nullptr) {
if (dirp->d_type ==
DT_REG) {
// 文件
printf(
"%s\n", dirp->
d_name);
} else if (dirp->d_type ==
DT_DIR) {
// 文件夹
}
}
closedir(dir);
return 0;
}
转载于:https://www.cnblogs.com/shixisheng/p/9199685.html