Skip to content

Instantly share code, notes, and snippets.

@fakenickels
Created September 22, 2012 21:02
Show Gist options
  • Save fakenickels/3767828 to your computer and use it in GitHub Desktop.
Save fakenickels/3767828 to your computer and use it in GitHub Desktop.
Organiza arquivos com um nome que contem um mesmo trecho de uma palavra
#!/usr/bin/ruby
# Example: wordor /anything/ ruby
# Found: anythingruby.pdf and rubynotify.rb, after put they in ruby/ folder
require 'find'
require 'fileutils'
if !ARGV.empty?
path = "#{ARGV[0]}/#{ARGV[1]}"
reg = /#{ARGV[1]}/
Dir.mkdir( path,0755 ) unless File.exists? path
Find.find( ARGV[0] ) do |f|
if f =~ reg && File.file?( f )
puts "Moving #{File.basename(f)}"
FileUtils.mv f, path
end
end
else
puts "how to use:\n\t wordor.rb path name"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment