views:

44

answers:

1

I have a zip file named test.zip which contains a directory named invoice. Inside the invoice directory there are documents each with different names. I would like to find a specific document named summary.txt which is inside the invoice directory.

I am able to get a handle to test.zip using the following:

zip = Zip::ZipFile.open("/path/to/test.zip")

but when I use

zip.find_entry("summary.txt")

I get nil.

On the other hand, if summary.txt is not inside the the invoices directory, but rather at the root of the zip file itself, the find_entry method as described above seems to work.

It seems that somehow I must navigate down into the invoices directory before searching for summary.txt.

Is this correct? If so, how do I do it? If not, what I am I doing wrong.

+1  A: 

You need to specify the full path to the file:

zip.find_entry 'invoices/summary.txt'
Mikael S
Do I have to specify the absolute path to the directory, or can it be relative?
rswolff
It has to be the absolut path, without a leading slash (/).
Mikael S