renaming multiple files in Perforce with the help of Ruby

Half an hour ago, I had about 60 files that had the same irritating prefix to the filename. I wanted to drop the prefix so the reader could see the significant portion of the filename first. There is no way that I would rename that many files by hand and not mess one up.

bad_path=/my_redundant_path/

def rename(file,path)
new_file = file.sub(path,”)
system(“p4 integrate #{file} #{new_file}”)
system(“p4 delete #{file}”)
end

Dir[“*.build”].each do |old_file|
rename(old_file,bad_path) if old_file.match(bad_path)
end

Two minutes spent playing with ruby goes a long way.

Tagged
%d bloggers like this: