Skip to content

Instantly share code, notes, and snippets.

@sferik
Created November 12, 2010 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sferik/674671 to your computer and use it in GitHub Desktop.
Save sferik/674671 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'fileutils'
require 'find'
usage_args = ['--usage', '--help', '-u', '-h']
if ARGV.length.eql? 0 or ARGV.length.eql? 1 and usage_args.include? ARGV[0]
puts "Usage: #{__FILE__} string_to_strip [directory]"
exit 0
end
# If the users specifies a directory, use it, otherwise default to the current directory
if(ARGV[1])
if(File.exists? ARGV[1])
Dir.chdir(ARGV[1])
else
puts "#{__FILE__}: Directory \"#{ARGV[1]}\" does not exist"
exit 0
end
end
wd = Dir.getwd
puts "#{__FILE__}: In: #{wd}"
files = []
Find.find(wd) do |path|
files << path
end
FileUtils.cd(wd)
count = 0
files.each do |file|
unless(file.gsub(ARGV[0], '').eql? file)
FileUtils.mv(file, file.gsub(ARGV[0], ''), :force => true, :verbose => false)
puts "#{__FILE__}: #{file} => #{file.gsub(ARGV[0], '')}"
count += 1
end
end
puts "#{__FILE__}: Complete: #{count} " + ((count.eql? 1) ? 'file' : 'files') + " striped of \"#{ARGV[0]}\""
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment