# How do I put empty directories into a gem package?

**URL:** <https://www.ruby-forum.com/t/how-do-i-put-empty-directories-into-a-gem-package/85241>\
**Category:** Ruby\
**Created:** [February 11, 2007, 10:40pm UTC](https://www.ruby-forum.com/t/how-do-i-put-empty-directories-into-a-gem-package/85241 "2007-02-11T22:40:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![luke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/7ab992/32.png) [@luke](https://www.ruby-forum.com/u/luke)\
**Post date:** [February 11, 2007, 10:40pm UTC](https://www.ruby-forum.com/t/how-do-i-put-empty-directories-into-a-gem-package/85241/1 "2007-02-11T22:40:52Z")

</div>

I feel like an idiot for being unable to get this working…

I’m trying to put together a general purpose “project templating  
engine” and I’d like to just package a directory full of project  
templates that get copied and rendered in ERB on demand. These  
templates often include empty directories that I can’t seem to get  
packaged into my gem - no matter what I do.

I’m pretty sure I’m doing something really dumb, but I can’t seem to  
figure out what it is!

It occurred to me that I might pack these templates up in a zip or tar  
file and just unpack them on request, but I couldn’t get the empty  
directories into the zip file either. At this point, that makes me  
think I’m just doing something wrong, so rather than going to the pack/  
unpack scheme - it seems like I ought to just ask you folks how to do  
it correctly.

So -

Does anyone know how to get empty directories into a gem package?

Here’s what I have in my rake file:

PKG\_LIST = FileList[’[a-zA-Z]_’,  
'bin/\*\*/_’,  
‘lib/**/\*’,  
‘templates’,  
'templates/**/_’,  
'templates/\*\*/.[a-z]_’  
]

PKG\_LIST.exclude(’.svn’)  
PKG\_LIST.each do |file|  
puts 'file: ’ + file  
task :package =\> file  
end

When I run “rake package”, I see all of the desired files _and_ all of  
the desired directories on screen, but when I install the gem, they’re  
not there!

I’m guessing there is some simple exclude directive that I’m not able  
to find? I dug around in the rake package task code, but can’t see  
anything obvious (to me at least)

Thanks,

lb.

---

<div class="post-metadata">

**Author:** ![luke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/7ab992/32.png) [@luke](https://www.ruby-forum.com/u/luke)\
**Post date:** [February 12, 2007, 1:15am UTC](https://www.ruby-forum.com/t/how-do-i-put-empty-directories-into-a-gem-package/85241/2 "2007-02-12T01:15:03Z")

</div>

On 2/11/07, Luke [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m trying to put together a general purpose “project templating  
> engine” and I’d like to just package a directory full of project  
> templates that get copied and rendered in ERB on demand. These  
> templates often include empty directories that I can’t seem to get  
> packaged into my gem - no matter what I do.

Um. I’m not sure that’s what you want to do. Why not consider  
approaching this from a slightly different perspective? Make a .tar.gz  
file that gets deployed with your other files and then use  
Archive::Tar::Minitar to unpack it on the fly (Ruwiki does this) and  
render with ERB as usual. Archive::Tar::Minitar can easily handle this  
on both ends and you don’t need to try to trick RubyGems.

-austin

---

<div class="post-metadata">

**Author:** ![luke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/7ab992/32.png) [@luke](https://www.ruby-forum.com/u/luke)\
**Post date:** [February 12, 2007, 1:46am UTC](https://www.ruby-forum.com/t/how-do-i-put-empty-directories-into-a-gem-package/85241/3 "2007-02-12T01:46:06Z")

</div>

I definitely considered that direction, and even got it mostly-  
working, but then I started having problems with my test cases.

I was writing tests that unpack the actual tarball and found that my  
tests now had a dependency on a successful build, but I couldn’t get a  
successful build unless my tests passed! ☹

I recognize that this is a simple problem and could be fixed by  
packing up the tarball in the test\_helper or setup methods, but then  
it felt like I was violating dry principles by putting my packing  
logic (more importantly - the file selection) into the rake file _and_  
into my test cases. I wanted to verify that the actual templates being  
shipped in the gem are in fact what we’re testing against, and I’d  
like the test cases stay up to date if our inclusion globs change over  
time…

This also puts another dependency into my gem and I was hoping to  
minimize those external dependencies.

It just feels like I’m missing some simple setting in the gem package  
task…

Something like:  
prune\_empty\_directories = false

Another reason I don’t want to tar them up, is because I’m optionally  
duplicating them into user\_home and/or project\_home, and I would  
prefer not to have different copy logic when they come out of  
gem\_home, and it’s essential that users can easily modify these  
templates when they’re placed into those other two locations - so they  
can’t be tarred up in there.

The final reason it felt strange to tar the templates was simply  
because my understanding is that gem is already tarring everything up,  
so shouldn’t I just be able to get that one working?

> Um. I’m not sure that’s what you want to do. Why not consider  
> approaching this from a slightly different perspective? Make a .tar.gz  
> file that gets deployed with your other files and then use  
> Archive::Tar::Minitar to unpack it on the fly (Ruwiki does this) and  
> render with ERB as usual. Archive::Tar::Minitar can easily handle this  
> on both ends and you don’t need to try to trick RubyGems.

Thanks for the response.

Luke  
[www.asunit.org](http://www.asunit.org)

---

<div class="post-metadata">

**Author:** ![luke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/7ab992/32.png) [@luke](https://www.ruby-forum.com/u/luke)\
**Post date:** [March 22, 2007, 10:47pm UTC](https://www.ruby-forum.com/t/how-do-i-put-empty-directories-into-a-gem-package/85241/4 "2007-03-22T22:47:43Z")

</div>

Does anyone else have any ideas about how to solve this problem?

For what it’s worth, I wound up writing a rake task that injects a  
bunch of junk files into the entire template directory and then added  
these file names to my “ignore list” when copying out of the installed  
gem.

Definitely _not_ elegant but it works.

Luke B.

---

<div class="post-metadata">

**Author:** ![luke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/7ab992/32.png) [@luke](https://www.ruby-forum.com/u/luke)\
**Post date:** [March 27, 2007, 10:18pm UTC](https://www.ruby-forum.com/t/how-do-i-put-empty-directories-into-a-gem-package/85241/5 "2007-03-27T22:18:00Z")

</div>

On Mar 22, 2007, at 14:45, Luke wrote:

> Does anyone else have any ideas about how to solve this problem?
> 
> For what it’s worth, I wound up writing a rake task that injects a  
> bunch of junk files into the entire template directory and then added  
> these file names to my “ignore list” when copying out of the installed  
> gem.
> 
> Definitely _not_ elegant but it works.

Please give some code that shows how this is broken.
