Created
August 22, 2011 19:55
-
-
Save gnarl/1163352 to your computer and use it in GitHub Desktop.
Unzip nested zip files to directories named after the zip filename.
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
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