The search would be something like this. Assume that the function file_exists(int n,char *dirpath) checks whether the file name whose index is 'n' (e.g. IMGL0011.JPG when n=11) exists within the directory whose pathname is "dirpath" and returns non-zero if it does.
I'm also assuming that a directory will have no more than 100 files numbered from 0 to 99.
int find_file(char *dirpath)
lo = 0;
hi = 99;
// Set up the initial conditions for the binary search that the first file (0) must exist
// and the last one (99) must not
// if index zero doesn't exist, it is the next file (or, at least, it indicates that
// this directory is empty)
// if index 99 does exist then this directory is full, return an error/full indication
mid = (hi-lo+1)/2;
// If the mid-point file exists, change the lo pointer
// otherwise change the hi pointer
if(file_exists(mid,dirpath)) lo = mid;
else hi = mid;
// If hi and lo are just one apart, we've found the boundary between the two
// and then next filename is hi
} while(hi-lo > 1);
If there are 1000 files per directory, just change "hi=99;" to "hi=999;". In that case, the number of tests will be a maximum of about 12 (including the two initial tests of 0 and 999).