Skip to content

Instantly share code, notes, and snippets.

@gnarl
Created August 22, 2011 19:55
Show Gist options
  • Save gnarl/1163352 to your computer and use it in GitHub Desktop.
Save gnarl/1163352 to your computer and use it in GitHub Desktop.
Unzip nested zip files to directories named after the zip filename.
require 'fileutils'
def unzip_dir(dir)
FileUtils.cd(dir)
top = Dir['*.zip']
top.each do |x|
if x.match(/.*\.zip\Z/)
begin
#puts "unzipping " + x
new_dir = x.sub(".zip", "")
#puts "make #{new_dir}"
FileUtils.mkdir(new_dir)
%x{unzip #{x} -d #{new_dir}}
FileUtils.rm(x)
rescue Exception => e
puts e
end
end
end
find_dirs()
FileUtils.cd('../')
end
def find_dirs
top = Dir["*"]
top.each do |x|
puts x
if File.directory?(x)
puts "unzip_dir(#{x})"
unzip_dir(x)
end
end
end
find_dirs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment