Skip to content

Instantly share code, notes, and snippets.

@choipd
Created April 21, 2016 14:29
Show Gist options
  • Save choipd/750657a7728c93bccabe76a086fbce27 to your computer and use it in GitHub Desktop.
Save choipd/750657a7728c93bccabe76a086fbce27 to your computer and use it in GitHub Desktop.
한글 CP949 압축된 파일 풀기
#!/usr/bin/ruby
require 'fileutils'
require 'zip'
def unzip
Zip::File.open(ARGV[0]) { |zipfile|
zipfile.each {|f|
# cp949 파일 이름을 utf-8로 변환
utf_string = f.name.force_encoding("CP949").encode("UTF-8", :invalid => :replace, :undef => :replace, :replace => "_") # for ruby1.9 or higher
FileUtils.mkdir_p(File.dirname(utf_string))
#zipfile.extract(f,utf_string)
f.extract(utf_string)
puts utf_string
}
}
end
unzip
@choipd
Copy link
Author

choipd commented Apr 21, 2016

dependance: gem install zip
usage:
ruby unzip_c949.rb a.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment