Skip to content

Instantly share code, notes, and snippets.

@rklemme
Created October 28, 2011 08:37
Show Gist options
  • Save rklemme/1321879 to your computer and use it in GitHub Desktop.
Save rklemme/1321879 to your computer and use it in GitHub Desktop.
Update newer files from one dir to another dir
#!/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