Skip to content

Instantly share code, notes, and snippets.

@donatj
Created January 22, 2013 23:24
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 donatj/4599802 to your computer and use it in GitHub Desktop.
Save donatj/4599802 to your computer and use it in GitHub Desktop.
Move Old Downloads - A simple script to move downloads to a sub-directory
#!/usr/bin/env ruby
path = File.expand_path('~/Downloads/');
older_path = File.join(path, 'Older')
days = 20
seconds_offset = ( days*24*60*60)
the_break = Time.now - seconds_offset
Dir.foreach(path) do |fname|
full_path = File.join(path, fname)
next if fname[0,1] == '.' or full_path == older_path
if File.atime( File.join(path, fname) ) < the_break
new_path = File.join(older_path, fname)
puts "#{full_path} » #{new_path}"
File.rename( full_path, File.join(older_path, fname) )
end
end
File.utime( the_break, the_break, File.join(path, 'Older') )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment