Subscribe to RSS Feed
Twitter
HIRE ME! home  archives  about  blogroll

Rename all files in dir

11 May 2004

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.

blog comments powered by Disqus