Created
August 22, 2014 13:58
-
-
Save CremboC/ee973fcbfca217f919f5 to your computer and use it in GitHub Desktop.
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
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