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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/889769/227415c000dbc82a1d726ad32c4a6e3e81f0faa1
Bug fix.