Skip to content

Instantly share code, notes, and snippets.

@takuya
Created Sep 25, 2014
Embed
What would you like to do?
#!/usr/bin/env ruby
#
#
require 'find'
require 'fileutils'
if ARGV.size != 2 then
puts "
散らばったファイルを一箇所にコピーして集めてくる
使い方 #{__FILE__} src dst
iMessageの添付ファイルをデスクトップに取り出す。
#{__FILE__} ~/Library/Messages/Attachments ~/Desktop
"
exit
end
src = ARGV.shift
dst = ARGV.shift
dst = File.dirname(dst) + "/" + File.basename(dst)
raise "destination #{dst} is not writable " unless File.writable? dst
def File.cp( src, dst)
raise "source #{src} is not readable " unless File.redable
raise "destination #{dst} is not writable " unless File.writable? dst
end
exit
Find.find(src).
reject{|e| File.directory? e}.
reject{|e| (File.basename(e) =~/^\./) != nil }.
each{|e|
org_name = File.basename(e)
f_name = File.basename(e)
cnt = 1
begin
dst_file = "#{dst}/#{f_name}"
raise if File.exists? dst_file
r = FileUtils.cp(e,dst )
rescue
cnt = cnt + 1
f_name = File.basename(org_name,File.extname(org_name)) +"."+ (cnt).to_s + File.extname(org_name)
puts f_name
retry
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment