Skip to content

Instantly share code, notes, and snippets.

@pinzolo
Last active August 29, 2015 14:05
Show Gist options
  • Save pinzolo/d640adbd65850054b6aa to your computer and use it in GitHub Desktop.
Save pinzolo/d640adbd65850054b6aa to your computer and use it in GitHub Desktop.
require 'zip'
class ZipForWin
def zip_files(directory)
Zip::File.open("#{directory}.zip", Zip::File::CREATE) do |zipfile|
# 再帰的にサブディレクトリも格納する
Dir[File.join(directory, '**', '**')].each do |entry|
# 相対パスで格納
entry_path = entry.sub(directory, '')
# windows で解凍できるように Shift_JIS へ変換
sjis_entry_path = entry_path.encode(Encoding::CP932, invalid: :replace, undef: :replace)
zipfile.add(sjis_entry_path, entry)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment