Gtk4-tutorial/lib/lib_cp_images.rb
2022-04-22 12:04:27 +09:00

19 lines
516 B
Ruby

require 'fileutils'
include FileUtils
def cp_images srcmdfiles, dst_dir
mkdir_p(dst_dir) unless Dir.exist?(dst_dir)
images = srcmdfiles.map do |file|
d = File.dirname(file)
f = File.read(file)
f = f.gsub(/^ .*\n/,'')
f = f.gsub(/^~~~.*?^~~~\n/m,'')
imgs = f.scan(/!\[.*?\]\((.*?)\)/).flatten.uniq
imgs.map{|img| File.absolute_path("#{d}/#{img}")}
end
images = images.flatten.sort.uniq
images.each do |src|
dst = "#{dst_dir}/#{File.basename(src)}"
cp(src, dst)
end
end