1

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?

1 Answer 1

2

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

5
  • 1
    If you want to keep the "png" and remove the "gif" you may be able to use mv "$file" "${file/.gif}" Commented Sep 16, 2010 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". Commented Sep 16, 2010 at 18:00
  • @Gilles: or ${file/.gif./.} Commented Sep 16, 2010 at 18:22
  • @Dennis: dodelijke.gif.fles.gif.png still kills you... Commented Sep 16, 2010 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. :( Commented Sep 16, 2010 at 19:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .