Aizen
Aizen

Reputation: 581

Reading Files from Directory one by one

I have files in a directory named as 1.txt ,2.txt and so on. I am reading these files by:

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); 

}

I have more than 800 txt files in the folder(1.txt - 800.txt). But when around 500 files are read i.e from 1.txt to 500.txt it exits and doesnot read the next files.

Can anyone rectify this problem? Thanx in advance.

Upvotes: 1

Views: 322

Answers (1)

baliman
baliman

Reputation: 620

Maybe you are running uout of file descriptors (max is for example 500 per process). Try to use the readdir function.

Upvotes: 1

Related Questions