Skip to content

Instantly share code, notes, and snippets.

@fukayatsu
Created August 10, 2013 15:13
Show Gist options
  • Save fukayatsu/6200779 to your computer and use it in GitHub Desktop.
Save fukayatsu/6200779 to your computer and use it in GitHub Desktop.
require 'zipruby'
require 'fileutils'
ROOT_DIR = File.expand_path(File.dirname(__FILE__))
Dir::glob("#{ROOT_DIR}/*.zip") do |zip_file|
folder_name = nil
Zip::Archive.open(zip_file) do |archive|
puts "extract: #{zip_file}"
archive.each do |zf|
if zf.directory?
FileUtils.mkdir_p(zf.name)
folder_name ||= zf.name[0...-1]
else
dirname = File.dirname(zf.name)
FileUtils.mkdir_p(dirname)
open(zf.name, 'wb') do |f|
f << zf.read
end
end
end
end
# dir rename
new_folder_name = File.basename(zip_file, ".*")
FileUtils.mv("#{ROOT_DIR}/#{folder_name}", "#{ROOT_DIR}/#{new_folder_name}")
# mv zip
FileUtils.mv(zip_file, "#{ROOT_DIR}/zip_done/")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment