Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- require 'FileUtils'
- require 'Pathname'
- require 'ftools'
- delay = 7 # minutes
- path = "/Users/tycale/Downloads/" # With / at the end
- todo = []
- def time_block
- start_time = Time.now
- yield
- return Time.now - start_time
- end
- def repeat_every(seconds)
- while true do
- sleep( seconds - time_block { yield } )
- end
- end
- repeat_every(60.0*delay) do
- p todo
- Dir.foreach(path) { |file|
- if !File.directory?(path+file) and file !~ /^\./
- ext = File.extname(path+file)
- name = File.basename(path+file, ext)
- if todo.include?(name)
- rep = case ext
- when ".dmg" then "dmg"
- when ".jpg" then "images"
- when ".png" then "images"
- when ".tiff" then "images"
- when ".gif" then "images"
- when ".pdf" then "pdf"
- when ".tar" then "tar"
- when ".exe" then "exe"
- when ".zip" then "zip"
- when ".bz2" then "bz2"
- when ".html" then "web"
- when ".htm" then "web"
- else "autres"
- end
- Dir.mkdir(path+rep) if !Pathname.new(path+rep).exist?
- File.move(path+file, path+rep+"/"+file, :verbose => true)
- end
- todo += [name]
- end
- }
- end
Add Comment
Please, Sign In to add comment