Skip to content

Instantly share code, notes, and snippets.

@CremboC
Created August 22, 2014 13:58
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 CremboC/ee973fcbfca217f919f5 to your computer and use it in GitHub Desktop.
Save CremboC/ee973fcbfca217f919f5 to your computer and use it in GitHub Desktop.
require 'fileutils'
if ARGV[0].nil? || ARGV[1].nil?
puts 'Must define where to and from to copy',
'Usage: movejars <from> <to>',
'May use . to say "current folder"'
exit 0
end
$from = ARGV[0].dup
$to = ARGV[1].dup
$from = Dir.pwd if $from == '.'
$to = Dir.pwd if $to == '.'
while true
puts 'Moving...'
Dir.entries($from).select {
|f|
if !File.directory? f
name_no_ext = f[/^[^.]*/]
oldpath = $from + '/' + f
newpath = $to + '/' + f
file = File.new(oldpath, "r")
if !File.exists? newpath or File.mtime(oldpath) > File.mtime(newpath)
puts 'Moved files' if FileUtils.copy_file(oldpath, newpath, true, false)
end
file.close
end
}
puts 'Sleeping...'
sleep 5
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment