It is working now regardless which folder you stored your RAW or JPG files. It will find them in any folder inside DCIM.
I struggled with it for days until I discovered you ALWAYS have to close the folders with
closedir(). The compiler doesn't warn you and you think your code is simply wrong. I will never forget to include this bloody command.
It works as follows:
First, you delete the outtakes in playback mode (using Canon's interface).
Then, to delete the corresponding RAW files, you go to CHDK File Browser, select DCIM folder, push left button to display the popup menu and select "Purge RAW". A warning will ask you to confirm and voila! You have regained some SD space.
This feature will search through all the folders in DCIM looking for a RAW file (CRW/CR2 prefix or file extension) and if it finds one then will look for its JPG partner anywhere inside DCIM (comparing the 4 digit number assigned by the camera). If it is not found, the RAW file is erased.
I forgot to take some shots of the screen, I will post some tomorrow. Don't tell Nikon I'm using their camera with the only puropose of showing CHDK in action.
See reply #31
You can try it here. Remember this is NOT an official build. The purpose should be testing the "Purge RAW" feature only. Do not use it with important shots. I think it should be tested in all cameras first. because deleting files is always a sensitive operation.
allbest-w-a460-100d-78.zip - 0.21MB
allbest-w-a5xx-all.zip - 0.62MB
allbest-w-a6xx-all.zip - 1.32MB
allbest-w-a7xx-all.zip - 0.49MB
allbest-w-g7-all.zip - 0.84MB
allbest-w-ixus-all.zip - 1.24MB
allbest-w-s2is-all.zip - 0.63MB
allbest-w-s3is-100a-78.zip - 0.21MB
Any comments/suggestions will be appreciated.
This is the function:
static void fselect_purge_cb(unsigned int btn) {
DIR *d, *d2, *d3, *d4;
struct dirent *de, *de2, *de3, *de4;
char sub_dir[20], sub_dir_search[20];
char selected_item[256];
int i, found=0;
if (btn==MBOX_BTN_YES) {
sprintf(current_dir+strlen(current_dir), "/%s", selected->name);
d=opendir(current_dir);
while ((de=readdir(d)) != NULL) {
if (de->name[0] != '.' && de->name[1] != '.') {//If item is a file
sprintf(sub_dir, "%s/%s", current_dir, de->name);
d2=opendir(sub_dir);
while ((de2=readdir(d2)) != NULL) {
if (de2->name[0] == 'C' || de2->name[9] == 'C') {//If file is RAW (Either CRW/CR2 prefix or file extension)
d3=opendir(current_dir);
while ((de3=readdir(d3)) != NULL) {
if (de3->name[0] != '.' && de3->name[1] != '.') {//If item is a file
sprintf(sub_dir_search, "%s/%s", current_dir, de3->name);
d4=opendir(sub_dir_search);
while ((de4=readdir(d4)) != NULL) {
if (de2->name[4] == de4->name[4] && de2->name[5] == de4->name[5] &&//If the four digits of the Canon number are the same
de2->name[6] == de4->name[6] && de2->name[7] == de4->name[7] &&
de4->name[9] == 'J' && !(de4->name[0] == 'C' || de4->name[9] == 'C' || de4->name[0] == 0xE5)) {//I file is JPG and is not CRW/CR2
started();
found=1;//A JPG file with the same Canon number was found
}
}
closedir(d4);
}
}
closedir(d3);
if (found == 0) {
sprintf(selected_item, "%s/%s", sub_dir, de2->name);
remove(selected_item);
finished();
}
else {
found=0;
finished();
}
}
}
closedir(d2);
}
}
closedir(d);
i=strlen(current_dir);
while (current_dir[--i] != '/');
current_dir[i]=0;
gui_fselect_read_dir(current_dir);
}
gui_fselect_redraw = 2;
}
Yes, I know, 4 nested
while loops, ugly.
Cheers!