我在名为 1.txt 、2.txt 等的目录中有文件。我正在通过以下方式阅读这些文件:
int counter=0;
unsigned char buffer[212]={0};
while(1)
{
sprintf(buffer,"path/%d.txt",++counter);
FILE *fp = fopen(buffer,"rb");
// some operations..
fclose(fp);
}
我的文件夹中有超过 800 个 txt 文件(1.txt - 800.txt)。但是当读取大约 500 个文件时 即从 1.txt 到 500.txt 它退出并且不读取下一个文件。
谁能解决这个问题?提前谢谢。
最佳答案
也许您的文件描述符用完了(例如每个进程最多 500 个)。尝试使用 readdir 函数。
关于c - 从目录中逐一读取文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8427567/