Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Add Comment
Please, Sign In to add comment