chdkptp uses
string.format('%s/IMG_%04d.JPG',get_image_dir(),get_exp_count())
in various places. Note this may not be 100% reliable in all cases on all cameras.
Also note that CHDK raw may be in a different directory, depending on menu settings. The chdkptp shoot command has examples of code which handles this.