开发者

How do I find a specific entry inside a zipped directory using the rubyzip gem?

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.


You need to specify the full path to the file:

zip.find_entry 'invoices/summary.txt'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜