Skip to content

Instantly share code, notes, and snippets.

@Amitesh
Created September 28, 2011 07:26
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save Amitesh/1247229 to your computer and use it in GitHub Desktop.
Save Amitesh/1247229 to your computer and use it in GitHub Desktop.
unzip folder in ruby
require 'rubygems'
require 'zip/zip'
def unzip_file (file, destination)
Zip::ZipFile.open(file) { |zip_file|
zip_file.each { |f|
f_path=File.join(destination, f.name)
FileUtils.mkdir_p(File.dirname(f_path))
zip_file.extract(f, f_path) unless File.exist?(f_path)
}
}
end
@jmccaffrey
Copy link

thanks

@MattStopa
Copy link

Thank you greatly. I hate the this ruby ZIP library with a passion. Why is there not Zip::ZipFile.extract that just works? :-(

@d1rtyvans
Copy link

Awesome thanks

@ankurdh
Copy link

ankurdh commented May 24, 2016

This is awesome. Thank you!

@city
Copy link

city commented Feb 6, 2018

Elegant!
used cd and then mkdir if doesn't exist not mkdir_p but this works too.

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