Thanks reyalp but it doesn't work 
Which part doesn't work? If you can't tell, my usual approach would be to add some print statements, and also check the return status of os.remove.
I think see my mistake though, idir just returns the file name, not the full path, so os.remove was just trying to remove ('FOO.CFG') or whatever. Also, Lua patterns used in match are case sensitive, so .cfg wouldn't have been found in the previous code.
Revised version (still untested):
for f in os.idir('A/CHDK/DATA') do
if f:match('%.[cC][fF][gG]$') or f:match('%.0$') then
if not os.remove('A/CHDK/DATA/'..f) then
error('remove failed')
end
end
end