» Ruby »
Pathname#dirnames method to iterate on parent directories


This gem has one method: Pathname#dirnames.

It will return an enumerable of pathnames created by calling #dirname repeatedly.

This can be useful for traversing directories upwards to parent, grandparent, etc.


 p ='/foo/goo/hoo.txt')
 #=> ['/foo/goo', '/foo', '/']

For docs go to

Want to help? We're happy to get pull requests.

Install quickstart


gem install sixarm_ruby_week


gem "sixarm_ruby_pathname_dirnames", "~>1.0.0"


require "sixarm_ruby_pathname_dirnames"

Install with security (optional)

To enable high security for all our gems:

gem cert --add sixarm.pem
gem sources --add

To install with high security:

gem install sixarm_ruby_pathname_dirnames --test --trust-policy HighSecurity

Example to find a file

To find the first occurance of a file named "my.txt" in a path or its parents:

 basename = "my.txt"
 p ='/foo/goo/hoo/*')
 puts p.dirnames.find{|dirname| (dirname + basename).exist?}

Note that the "" at the end of the pathname is to give dirname something to chop off; the "" is being used as chaff, not as a file matcher nor string matches.


  • 2012-03-22 1.0.0 Created


You may choose any of these open source licenses:

  • Apache License
  • BSD License
  • CreativeCommons License, Non-commercial Share Alike
  • GNU General Public License Version 2 (GPL 2)
  • GNU Lesser General Public License (LGPL)
  • MIT License
  • Perl Artistic License
  • Ruby License

The software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement.

In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.

This license is for the included software that is created by SixArm; some of the included software may have its own licenses, copyrights, authors, etc. and these do take precedence over the SixArm license.

Copyright (c) 2013 Joel Parker Henderson