Ok, now I can searh in every folder inside DCIM with this code:
int main() {
DIR *d, *d2;
struct dirent *de, *de2;
int found=0;
char sub_dir[256];
char current_dir[20]="DCIM";
printf("Opening main folder %s", current_dir);
d=opendir(current_dir);
de=readdir(d);
while (de) {//For all folders in DCIM
if (de->d_name[3] == 'C' && de->d_name[4] == 'A') {//Is the item a folder?
printf("\nFound a Canon sub folder");
sprintf(sub_dir, "%s/%s", current_dir, de->d_name);
printf("\nOpening Canon sub folder %s", de->d_name);
d2=opendir(sub_dir);
de2=readdir(d2);
while (de2) {
if (de2->d_name[0] == 'C' || de2->d_name[9] == 'C' && !(de->d_name[0] == '.' || de->d_name[1] == '.' || de->d_name[2] == '0')) {//Is the item a RAW file?
printf("\nFound RAW file %s", de2->d_name);
}
de2 = readdir(d2);
}
printf("\nExit sub folder %s", sub_dir);
}
de = readdir(d);
}
printf("\nExit main folder %s", current_dir);
getch();
}
Note that this code does not run in the camera but in the PC. I got tired of loading the SD card from the PC to the camera every time. Once this works it is only a matter of copy it to the trunk an change 2 or 3 lines. (Of course you have to use the same arm gcc compiler for execute in the PC).
Well, the problem of RAW files in different location than the JPG can be solved by duplicating this code. One time to search ALL of the RAW files and the second to search ALL the corresponding JPGs. But my concern is as follows: AFAIK the bug GrAnd mentioned involves ONLY ONE RAW file in a different folder so I wonder if a complete DCIM tree search is worth for ONLY ONE file. I think not.
Because of this I was thinking to write the code to detect when the user has specified a special folder for RAWs in the CHDK RAW menu and use that folder in the search. On the other hand, if the user is writing the RAWs in the same folder than JPGs the problem is already solved with the first piece of code in this thread. This way we avoid a double search in the DCIM tree. I hope I am clear with my limited English.
I'd appreciate your input.