Hello all,
It’s near about 3 months since i wrote last blog entry(ok, that too was a coming soon). In these three months had many ideas to write about, but couldn’t realize. Today i wrote one script or should i say single line command to rename all the files in a folder conditionally, so i though let’s start blogging with this and kick start it again.
My need was to rename all the images in a folder having .png extension. These files were with ’35px-’ prefix and were having ‘-icon’ before .png extension. So using ruby + shell script i found all the images with .png extension and renamed them with mv command, just that while renaming, i replaced ’35px-’ and ‘-icon’ part using gsub function provided by ruby.
This is my code. You can even use cp command rather than mv, so that you will have second set of images, rather than loosing the original images directly. You can even copy them elsewhere with cp and proving path as second argument.
#on shell....
ruby -e 'Dir.glob("*.png").each{|i| `mv #{i} #{i.gsub("35px-", "").gsub("-icon","")}`}'
Will try to find the complete shell way for this.