I have about 200 images that I optimized with PunyPNG, but it appended .png to the end so all of the images are .gif.png. I don't want to have to manually edit the file name of each one to just be .gif, so what would be the easiest way to automatically remove the .png from the end of all of the file names in the folder?

link|improve this question

feedback

1 Answer

up vote 2 down vote accepted

First, please make sure that these are actually .gif files and not .png files. (It seems more likely that they are misnamed .png's rather than misnamed .gif's, but if you're sure...)

Open the terminal.

Type in:

cd "/folder/in/question" (replace with actual folder name)

Press enter. Type in:

for file in *.gif.png ; do mv "$file" "${file%.png}" ; done

link|improve this answer
1  
If you want to keep the "png" and remove the "gif" you may be able to use mv "$file" "${file/.gif}" – Dennis Williamson Sep 16 '10 at 1:35
@Dennis: It's all fun and games until you get to Christmas.gift.gif.png... If you want to keep the .png, use mv "$file" "${file%.gif.png}.png". – Gilles Sep 16 '10 at 18:00
@Gilles: or ${file/.gif./.} – Dennis Williamson Sep 16 '10 at 18:22
@Dennis: dodelijke.gif.fles.gif.png still kills you... – Gilles Sep 16 '10 at 18:37
@Gilles: You've checkmated me (but there's always ${file/%.gif.png/.png} as my consolation prize). It's no consolation that it's two characters longer than yours. :( – Dennis Williamson Sep 16 '10 at 19:15
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.