Skip to content

Instantly share code, notes, and snippets.

@cameck
Last active January 15, 2017 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cameck/e35b43a89f0310a2e86742285c38f0eb to your computer and use it in GitHub Desktop.
Save cameck/e35b43a89f0310a2e86742285c38f0eb to your computer and use it in GitHub Desktop.
# Thanks to http://www.markhneedham.com/blog/2008/10/02/ruby-unzipping-a-file-using-rubyzip/
require 'zip/zip'
def unzip_file(file, destination)
files = Zip::ZipFile.open(file) do |zip_file|
zip_file.each do |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
end
files.collect! { |f| "./#{f.name}" }
end
unzipped_files = unzip_file('cats.zip', './cat_files/')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment