# RubyZipFIleSystem - help with simple task

**URL:** <https://www.ruby-forum.com/t/rubyzipfilesystem-help-with-simple-task/144132>\
**Category:** Ruby\
**Created:** [July 25, 2008, 6:04pm UTC](https://www.ruby-forum.com/t/rubyzipfilesystem-help-with-simple-task/144132 "2008-07-25T18:04:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nathandelane](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@nathandelane](https://www.ruby-forum.com/u/nathandelane)\
**Post date:** [July 25, 2008, 6:04pm UTC](https://www.ruby-forum.com/t/rubyzipfilesystem-help-with-simple-task/144132/1 "2008-07-25T18:04:06Z")

</div>

I am new to Ruby, but am doing my best. I have a zip file that I’m  
trying to open, go to directory “word” and read one of the files out.  
Here is what I have so far:

require ‘rubygems’  
require ‘zip/zipfilesystem’

Zip::ZipFile.open(“Evelyn Attwood.docx.zip”) {  
|zipfile|  
zipfile.dir.open(“word”)  
puts zipfile.file.read(“document.xml”)  
}

Simple, but I get an error:

ruby docxreader.rb  
/Library/Ruby/Gems/1.8/gems/rubyzip-0.9.1/lib/zip/zipfilesystem.rb:371:in  
`stat': No such file or directory - word (Errno::ENOENT) from /Library/Ruby/Gems/1.8/gems/rubyzip-0.9.1/lib/zip/zipfilesystem.rb:463:in`foreach’  
from  
/Library/Ruby/Gems/1.8/gems/rubyzip-0.9.1/lib/zip/zipfilesystem.rb:458:in  
`entries' from /Library/Ruby/Gems/1.8/gems/rubyzip-0.9.1/lib/zip/zipfilesystem.rb:430:in`new’  
from  
/Library/Ruby/Gems/1.8/gems/rubyzip-0.9.1/lib/zip/zipfilesystem.rb:434:in  
`open' from docxreader.rb:6 from /Library/Ruby/Gems/1.8/gems/rubyzip-0.9.1/lib/zip/zip.rb:1382:in`open’  
from docxreader.rb:4

But there is certainly such a file. What am I doing wrong?

Much thanks,

Nathan

---

<div class="post-metadata">

**Author:** ![nathandelane](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@nathandelane](https://www.ruby-forum.com/u/nathandelane)\
**Post date:** [July 25, 2008, 6:39pm UTC](https://www.ruby-forum.com/t/rubyzipfilesystem-help-with-simple-task/144132/2 "2008-07-25T18:39:21Z")

</div>

Probably this archive does not contain the folder.  
Please try out:

require ‘rubygems’  
require ‘zip/zipfilesystem’

Zip::ZipFile.open(“Evelyn Attwood.docx.zip”) do |zipfile|  
puts zipfile.file.read(‘word/document.xml’)  
end

---

<div class="post-metadata">

**Author:** ![nathandelane](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@nathandelane](https://www.ruby-forum.com/u/nathandelane)\
**Post date:** [July 25, 2008, 6:45pm UTC](https://www.ruby-forum.com/t/rubyzipfilesystem-help-with-simple-task/144132/3 "2008-07-25T18:45:11Z")

</div>

Maciej Tomaka wrote:

> Probably this archive does not contain the folder.  
> Please try out:
> 
> require ‘rubygems’  
> require ‘zip/zipfilesystem’
> 
> Zip::ZipFile.open(“Evelyn Attwood.docx.zip”) do |zipfile|  
> puts zipfile.file.read(‘word/document.xml’)  
> end

That works! Thank you. Can you explain why though? When I unzip the  
archive, I see the folder. Is there a difference between a “directory”  
and a folder in a zip file?

---

<div class="post-metadata">

**Author:** ![nathandelane](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@nathandelane](https://www.ruby-forum.com/u/nathandelane)\
**Post date:** [August 7, 2008, 1:51pm UTC](https://www.ruby-forum.com/t/rubyzipfilesystem-help-with-simple-task/144132/4 "2008-08-07T13:51:06Z")

</div>

Nathan L. wrote:

> Maciej Tomaka wrote:
> 
> > Probably this archive does not contain the folder.  
> > Please try out:
> > 
> > require ‘rubygems’  
> > require ‘zip/zipfilesystem’
> > 
> > Zip::ZipFile.open(“Evelyn Attwood.docx.zip”) do |zipfile|  
> > puts zipfile.file.read(‘word/document.xml’)  
> > end
> 
> That works! Thank you. Can you explain why though? When I unzip the  
> archive, I see the folder. Is there a difference between a “directory”  
> and a folder in a zip file?  
> There is no folder/directory difference - it is the same thing. But you  
> may have it included in file or not.

Example:

$ zip document.zip document/sample.xml  
adding: document/sample.xml (stored 0%)

$ unzip -l document.zip  
Archive: document.zip  
Length Date Time Name

* * *

```
    0 08-07-08 13:39 document/
    0 08-07-08 13:39 document/sample.xml

```

* * *

```
    0 2 files

```

But if you create it using file-roller you don’t have directory  
included:

$ unzip -l document.zip  
Archive: document.zip  
Length Date Time Name

* * *

```
    0 08-07-08 13:39 document/sample.xml

```

* * *

```
    0 1 file

```

Thats all. 🙂

Best Regards

Maciej
