Skip to content

Instantly share code, notes, and snippets.

@novogrammer
Last active December 9, 2015 11:57
Show Gist options
  • Save novogrammer/5e1b8a41733525d823a1 to your computer and use it in GitHub Desktop.
Save novogrammer/5e1b8a41733525d823a1 to your computer and use it in GitHub Desktop.
差分納品につかうやつ。変更の無いファイルを消すスクリプト。
#!/usr/bin/env ruby
require "pathname"
def usage
puts "Usage:"
puts "\t#{$0} SRC_DIR DST_DIR"
exit false
end
def is_same?(a,b)
return [a,b].all?{|i|i.file? && i.exist?} && (a.read==b.read)
end
usage unless ARGV.length==2
src_dir=Pathname.new(ARGV[0])
dst_dir=Pathname.new(ARGV[1])
Pathname.glob(dst_dir.join("**/*")) do|dst_file|
rel_path=dst_file.relative_path_from(dst_dir)
src_file=src_dir.join(rel_path)
dst_file.delete if is_same?(src_file,dst_file)
end
system("find #{dst_dir} -name \".DS_Store\" -delete")
system("find #{dst_dir} -type d -empty -delete")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment