Created
March 27, 2011 23:46
-
-
Save ne-sachirou/889769 to your computer and use it in GitHub Desktop.
Simple unzip by Ruby and by JScript.
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
// http://d.hatena.ne.jp/hetappi/20080819/1219157144 | |
function unzip(zipfile, // @param String: Zipped file path | |
unzipdir) { // @param String: Unzip target directory path | |
var fso = new ActiveXObject('Scripting.FileSystemObject'), | |
shell = new ActiveXObject('Shell.Application'), | |
dst, zip; | |
if (!unzipdir) { | |
unzipdir = '.'; | |
} | |
if (!fso.FolderExists(unzipdir)) { | |
fso.CreateFolder(unzipdir); | |
} | |
dst = shell.NameSpace(fso.getFolder(unzipdir).Path); | |
zip = shell.NameSpace(fso.getFile(zipfile).Path); | |
if (fso.FileExists(zipfile)) { | |
dst.CopyHere(zip.Items(), 4 + 16); | |
} | |
} |
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
#License: Public Domain | |
require 'zip/zip' | |
# Unzip ziped file. | |
# unzip_file 'under/from.zip', '.' | |
def unzip_file zip_filename, target_foldername | |
Dir.mkdir target_foldername unless File.exist? target_foldername | |
Zip::ZipFile.foreach zip_filename do |zipentry| | |
puts target = "#{target_foldername}/#{zipentry.name}" | |
if zipentry.file? | |
destdirs = File.dirname(target).split('/') | |
destdirs.each_index {|i| Dir.mkdir destdirs[0..i].join('/') unless File.exist? destdirs[0..i].join('/')} | |
File.delete target if File.exist? target | |
zipentry.extract target | |
end | |
end | |
end |
https://gist.github.com/889769/d645d45a1dd31c24b6a2028d168fb33bb5e652fc
Fix license (for Ruby ver.).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/889769/d91d20e49b32363d7331eb25a0b05ca7b90ee3da
Bug fix for when zip file contain imaginally top directory.