Created
October 28, 2011 08:37
-
-
Save rklemme/1321879 to your computer and use it in GitHub Desktop.
Update newer files from one dir to another dir
This file contains hidden or 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/env ruby19 | |
# Read a directory tree and convert newer sources | |
# on the fly. | |
require 'pathname' | |
EXTENSIONS=%w{.jpg .JPG} | |
abort 'Need two arguments' unless ARGV.size >= 2 | |
from = Pathname.new(ARGV.shift) | |
to = Pathname.new(ARGV.shift) | |
abort 'Need source directory' unless from.directory? | |
from.find do |source| | |
if EXTENSIONS.include? source.extname | |
target = to + source.relative_path_from(from) | |
if !target.exist? || target.mtime < source.mtime | |
target.parent.mkpath | |
puts "Updating #{source} -> #{target}" | |
system 'touch', target.to_s | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment