Created
September 22, 2012 21:02
-
-
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
This file contains 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/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