10

Assuming a directory structure of:

a/b/c/d/e/f/g/h

I am trying to find 'h' via:

Dir.glob('a/**/f/g/h')

However this is not working. Any ideas?

You can try the test case below:

$ /usr/bin/ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
$ mkdir -p a/b/c/d/e/f/g/h
$ ruby -e "puts Dir.glob('a/**/*')"
a/b
a/b/c
a/b/c/d
a/b/c/d/e
a/b/c/d/e/f
a/b/c/d/e/f/g
a/b/c/d/e/f/g/h
$ ruby -e "puts Dir.glob('a/**/h')"
a/b/c/d/e/f/g/h
$ ruby -e "puts Dir.glob('a/**/g/h')"
a/b/c/d/e/f/g/h
$ ruby -e "puts Dir.glob('a/**/f/g/h')"
**nothing**
Jason Ling
  • 261
  • 2
  • 6
  • 3
    The more I dig into this, the more I think it may be a bug worth reporting upstream. It seems the match fails whenever there's more than two trailing path elements. My answer below addresses the current behavior, but it probably *is* a bug in Dir#glob, since File#fnmatch works correctly. – Todd A. Jacobs Sep 03 '12 at 06:14
  • I think it's a bug too. On REE 1.8.7, the last command has output as expected. – Tim Peters Sep 04 '12 at 00:35
  • Bug report link: http://bugs.ruby-lang.org/issues/6977 – Marc-André Lafortune Sep 05 '12 at 03:27

1 Answers1

2

This is a bug and has been solved with changeset r36905. Yay!

https://bugs.ruby-lang.org/issues/6977

Jason Ling
  • 261
  • 2
  • 6