I have a zip file which on first ‘level’ contains only directory. Something like:
some_file.zip
/ Opened file (level 1)
-> Directory/
/ level 2
-> file.txt
-> file2.txt
Can somebody write code how to cd to a Directory\ and list all entries?
I have written code but it doesnt work:
require 'zip/zipfilesystem'
Zip::ZipFile.open("./some_file.zip") do |zipfile|
zipfile.each_with_index do |file, index|
puts "inspect file == #{file.inspect}"
puts "entries == #{ zipfile.entries }"
entries = zipfile.entries
puts "zipfile.open file #{ zipfile.read(file) }"
end
end
PS I use rubyzip https://github.com/aussiegeek/rubyzip
Your code seems a bit too complicated. Suppose you have a zip file like this:
Then you can list the contents of the zip file using the
entriesmethod like in the following example:This little example produces the following output: