Koen's blog Profile Photo

Koen's blog

Ik typ. Ik typ voor mijn Sien, Arwen, Mila en Nienke.

Rename all files in dir

I wanted to rename all my pics in a directory to 1.jpg, 2.jpg, 3.jpg, and so on. You’ve got the picture, right? ;)

So once again, ruby to the rescue:

i = 0 Dir["*"].each { |f| File.rename(f, (i+=1).to_s + “.jpg” ) }

Maybe some ruby-guru’s can come up with something better, but this bit of code did the trick.