Created
July 5, 2011 00:02
-
-
Save leandrosilva/1064078 to your computer and use it in GitHub Desktop.
Command line utility to replace file names
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # Example: | |
| # | |
| # $ ./replacer foo bar *.* | |
| # | |
| # foo.app > bar.app | |
| # foo.erl > bar.erl | |
| # foo_app.erl > bar_app.erl | |
| # foo_sup.erl > bar_sup.erl | |
| # foo_deps.erl > bar_deps.erl | |
| # foo_server.erl > bar_server.erl | |
| from = ARGV[0] | |
| to = ARGV[1] | |
| puts "Replacing '#{from}' to '#{to}' in the file names" | |
| ARGV.each do |current_file| | |
| next if current_file == from or current_file == to | |
| next unless File.exist? current_file | |
| next unless current_file.include? from | |
| new_file = current_file.gsub(from, to) | |
| puts "#{current_file} > #{new_file}" | |
| File.rename current_file, new_file | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment