LoginSignup
21
20

More than 5 years have passed since last update.

zipファイルを展開する

Posted at

事前にgem install rubyzipでgemをインストールしておく。

以下のようなコードでzipファイルからファイルを展開することができる。

unzip.rb
require 'zip/zip'

Zip::ZipFile.open("hoge.zip") do |zip|
  zip.each do |entry|
    puts "entry #{entry.to_s}"
    # { true } は展開先に同名ファイルが存在する場合に上書きする指定
    zip.extract(entry, entry.to_s) { true }
  end
end

参考

21
20
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
20