利用したのは rubyzip/rubyzip の v1.1.6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
実際に使用する際には、外部から Shift_JIS か UTF8 かを選べるようにするのがいいかもね。
0 件のコメント :
コメントを投稿