# Is this a Ruby bug in Dir on Windows?

**URL:** <https://www.ruby-forum.com/t/is-this-a-ruby-bug-in-dir-on-windows/118322>\
**Category:** Ruby\
**Created:** [October 25, 2007, 6:42pm UTC](https://www.ruby-forum.com/t/is-this-a-ruby-bug-in-dir-on-windows/118322 "2007-10-25T18:42:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wemagor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/8edcca/32.png) [@wemagor](https://www.ruby-forum.com/u/wemagor)\
**Post date:** [October 25, 2007, 6:42pm UTC](https://www.ruby-forum.com/t/is-this-a-ruby-bug-in-dir-on-windows/118322/1 "2007-10-25T18:42:11Z")

</div>

This was discussed on another thread, but I thought I’d ask the question  
here to see if this is a bug or if it should work this way.

This line doesn’t seem work from the Windows root directory (C:) but  
works from a subdir.

ruby -e ‘puts Dir.glob(“/\*\*/\*.txt”)’ # Prints nothing

Here’s some commentary from the other thread:

On Oct 24, 1:07 pm, Wayne M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Tim McIntyre wrote:
> 
> > files = Dir.glob(“img/\*\*/\*.jpg”)
> 
> Why doesn’t that seem to work for me on Windows? Is there something  
> different about it on Windows than on Linux?
> 
> Is there something different about being at the top-level directory on  
> Windows? It’s unexpected behavior for me. Why does it operate like  
> that?

Looks like it behaves oddly at the root:  
C:\>irb  
irb(main):001:0\> Dir.glob( ‘./**/\*.rb’ ).length  
=\> 2  
irb(main):002:0\> Dir.chdir( ‘c:/documents and settings/gavin.kistner/  
desktop’ )  
=\> 0  
irb(main):003:0\> Dir.glob( './**/_.rb’ ).length  
=\> 638  
irb(main):004:0\> Dir.chdir( ‘c:/’ )  
=\> 0  
irb(main):005:0\> Dir.glob( './\*\*/_.rb’ ).length  
=\> 2  
irb(main):006:0\> Dir.glob( ‘.\*\*\*.rb’ ).length  
=\> 0

Further evidence, showing that it’s not an issue with \*\* not diving  
more than a couple levels deep:

C:\tmp\>irb  
irb(main):001:0\> Dir.glob( ‘./**/\*.rb’ )  
=\> [“./l1/l1.rb”, “./l1/l2/l2.rb”, “./l1/l2/l3/l3.rb”, “./l1/l2/l3/l4/  
l4.rb”]  
irb(main):002:0\> Dir.chdir( ‘…’ )  
=\> 0  
irb(main):003:0\> Dir.glob( './**/_.rb’ )  
=\> [“./const\_alias1.rb”, “./const\_alias2.rb”]  
irb(main):004:0\> Dir.glob( 'tmp/\*\*/_.rb’ )  
=\> [“tmp/l1/l1.rb”, “tmp/l1/l2/l2.rb”, “tmp/l1/l2/l3/l3.rb”, “tmp/l1/  
l2/l3/l4/l4.rb”]

Smells like a bug to me, but that’s a dangerous claim for someone who  
hasn’t looked at the implementation. Certainly unexpected behavior by  
me, too.

---

<div class="post-metadata">

**Author:** ![wemagor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/8edcca/32.png) [@wemagor](https://www.ruby-forum.com/u/wemagor)\
**Post date:** [October 26, 2007, 1:26am UTC](https://www.ruby-forum.com/t/is-this-a-ruby-bug-in-dir-on-windows/118322/2 "2007-10-26T01:26:56Z")

</div>

This is an educated guess, but i suspect it has to do with the way  
Windows handles accounts. This program at root will try to go into  
/documents and settings/administrator , when it trys to access this  
folder Windows will deny the program access. So before it hits  
administrator or some other folder that Windows wont allow ruby access  
to, it may have found 2 .rb (ruby applications) files in say User  
Documents.

- Mac
