ruby ruby ruby ruby

03.04.08

Filed Under: random

A couple recent projects have required a lot of files - such as images for a gallery or when i’ve converted a video to an image sequence - and i’ve often needed to rename these files. Fortunately for me, I work with a ruby-star (blogroll: Jason Cale) and he gave me this:

Dir.glob(”*”).each {|f| File.rename(f, f.gsub(”pattern”, “replacement”))}

Finds any occurrence of ‘pattern’ in any of the file names in a directory - and replaces it with ‘replacement’. Great times.

Comments are closed.

Categories