renaming multiple files in Perforce with the help of Ruby

by simpsonjulian on March 19, 2008

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.

Share with the group:
  • Digg
  • del.icio.us
  • Facebook
  • DZone
  • LinkedIn
  • Slashdot
  • StumbleUpon

Related posts:

  1. The quest for a decent Ruby Continuous Integration tool Git has become very popular in the Ruby community. Github...
  2. Every Continuous Integration server that supports Ruby + Git As I posted, I’m on a quest for the...

Related posts brought to you by Yet Another Related Posts Plugin.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous post: Ant Best Practices: Prefer a single buildfile

Next post: My article on Refactoring Ant Builds is published