I have a script that renames files from a .csv file, this file works fine but am looking to edit it a little bit more so that it help me even more.
The scenario is I
The Ruby file class has a rename()
method. So you could search for the files you want to rename then use the File.rename()
method to rename all of them.
Example:
product_name = "Some String";
id = 0;
filenames = Dir.glob("*.jpg")
filenames.each do |filename|
File.rename(filename, product_name + id.to_s)
id += 1
end
Here's a little tidbit for you. Maybe it will help out. http://rtdptech.com/2010/08/ruby-shell-script-to-rename-files-in-a-folder/
I used something like this for a quickie because I wanted to use the rdoc/ri files to make little examples. I copied some directories to another location and the wanted to change the extension from *.ri to *.rb so I could put my runnable ruby code in.
here's the command line version
$ ruby -e "Dir.glob('*/*.ri').each {|i| File.rename(i, i.gsub('ri', 'rb'))}"
and here is file version
Dir.glob('*/*.ri').each {|i| File.rename(i, i.gsub('ri', 'rb'))}