Skip to content

Instantly share code, notes, and snippets.

@tanaka51
Created June 21, 2013 09:34
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 tanaka51/5830074 to your computer and use it in GitHub Desktop.
Save tanaka51/5830074 to your computer and use it in GitHub Desktop.
find-cp png jpg -o ~/path/to/directory
#!/usr/bin/env ruby
require 'fileutils'; include FileUtils
require 'optparse'
dest_path = ""
noop = ""
opt = OptionParser.new
opt.on('-o VAL') {|v| dest_path = v }
opt.on('-d', '--dry-run') {|v| noop = v }
opt.on('-f', '--force') {|v| noop = !v }
noop ||= true
files = []
opt.permute(ARGV).reduce(files){|fs, extension| fs << `find . -name "*.#{extension}"`.split }
files.flatten.each {|f| cp f, dest_path + '/' + f[1..-1].gsub('/', '_'), noop: noop, verbose: true }
@tanaka51
Copy link
Author

ディレクトリ指定するのに -o ってオプションは何か違う気もした

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment