# A lot of directories each with a .zip

**URL:** <https://www.ruby-forum.com/t/a-lot-of-directories-each-with-a-zip/115854>\
**Category:** Ruby\
**Created:** [September 29, 2007, 7:53am UTC](https://www.ruby-forum.com/t/a-lot-of-directories-each-with-a-zip/115854 "2007-09-29T07:53:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![simonsaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5e925/32.png) [@simonsaid](https://www.ruby-forum.com/u/simonsaid)\
**Post date:** [September 29, 2007, 7:53am UTC](https://www.ruby-forum.com/t/a-lot-of-directories-each-with-a-zip/115854/1 "2007-09-29T07:53:37Z")

</div>

I could go about this a bunch of different ways. my lame bash skills  
came up with:

ls -R | grep “zip” | unzip -d /targetdir , which didn’t work (I get  
confused with the pipes and the input and the whatnot.)

but that’s okay, I’d rather just do it all inside ruby. so, I got the  
rubyzip gem, but am not finding any examples on how to use it (and I’m  
still confused about how to read the documentation) but rubyzip + rio  
seems like how I’ll go about it, since I’m using rio in other areas  
already.

any help on either doing it all in ruby, or the simple bash command  
I’m failing to execute, would be helpful 🙂 thank you much!

---

<div class="post-metadata">

**Author:** ![simonsaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5e925/32.png) [@simonsaid](https://www.ruby-forum.com/u/simonsaid)\
**Post date:** [September 29, 2007, 9:03am UTC](https://www.ruby-forum.com/t/a-lot-of-directories-each-with-a-zip/115854/2 "2007-09-29T09:03:08Z")

</div>

Hi,

On 9/28/07, Simon S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> already.
> 
> any help on either doing it all in ruby, or the simple bash command  
> I’m failing to execute, would be helpful 🙂 thank you much!

I don’t know anything about the ruby module, but I think this bash  
command should work:

find . -name “\*.zip” -type f -exec unzip -d /targetdir {} ;

Cameron

---

<div class="post-metadata">

**Author:** ![simonsaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5e925/32.png) [@simonsaid](https://www.ruby-forum.com/u/simonsaid)\
**Post date:** [September 29, 2007, 10:42am UTC](https://www.ruby-forum.com/t/a-lot-of-directories-each-with-a-zip/115854/3 "2007-09-29T10:42:33Z")

</div>

On 9/29/07, Cameron M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On 9/28/07, Simon S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > I could go about this a bunch of different ways. my lame bash skills  
> > came up with:
> > 
> > ls -R | grep “zip” | unzip -d /targetdir , which didn’t work (I get  
> > confused with the pipes and the input and the whatnot.)

> but I think this bash  
> command should work:
> 
> find . -name “\*.zip” -type f -exec unzip -d /targetdir {} ;

I think the above is the best. Other way if you really want to use  
grep and send the output to another command like unzip would be:

find . | grep “.zip” | xargs unzip

Jesus.

---

<div class="post-metadata">

**Author:** ![simonsaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5e925/32.png) [@simonsaid](https://www.ruby-forum.com/u/simonsaid)\
**Post date:** [September 29, 2007, 10:17am UTC](https://www.ruby-forum.com/t/a-lot-of-directories-each-with-a-zip/115854/4 "2007-09-29T10:17:59Z")

</div>

Simon S. wrote:

> I could go about this a bunch of different ways. my lame bash skills  
> came up with:
> 
> ls -R | grep “zip” | unzip -d /targetdir , which didn’t work (I get  
> confused with the pipes and the input and the whatnot.)
> 
> any help on either doing it all in ruby, or the simple bash command  
> I’m failing to execute, would be helpful 🙂 thank you much!

ls -R | grep zip (you don’t need quotes)

produces something like this:

aaa.zip  
bbb.zip  
cccc.zip

but there are no path names associated with those file names. I imagine  
unzip needs to know the full path to the file in order to unzip  
it–unless the file happens to be in the current directory.
