# Bug in Dir.glob in 1.8.6 on Windows?

**URL:** <https://www.ruby-forum.com/t/bug-in-dir-glob-in-1-8-6-on-windows/104425>\
**Category:** Ruby\
**Created:** [May 17, 2007, 9:35pm UTC](https://www.ruby-forum.com/t/bug-in-dir-glob-in-1-8-6-on-windows/104425 "2007-05-17T21:35:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tlockney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5e9695/32.png) [@tlockney](https://www.ruby-forum.com/u/tlockney)\
**Post date:** [May 17, 2007, 9:35pm UTC](https://www.ruby-forum.com/t/bug-in-dir-glob-in-1-8-6-on-windows/104425/1 "2007-05-17T21:35:23Z")

</div>

Hi,

I got a bug report for webgen which appeared when the user change from  
ruby 1.8.5 to 1.8.6 using the One-Click-Ruby-Installer. Following is  
an extract from an IRB session under Windows with ruby 1.8.6:

irb(main):005:0\> Dir[‘src/ **/** ’]  
=\> [“src/about.de.page”, “src/about.page”, “src/default.css”, “src/  
defau  
lt.template”, “src/images”, “src/images/bodybg.gif”, “src/images/  
boxbg.g  
if”, “src/images/greypx.gif”, “src/images/header.jpg”, “src/images/  
inner  
bg.gif”, “src/images/leaves.jpg”, “src/images/tabs.gif”, “src/  
index.de.p  
age”, “src/index.page”, “src/links.de.page”, “src/links.page”]  
irb(main):006:0\> Dir[‘src/ **/** /’]  
=\> [“src/”, “src/about.de.page/”, “src/about.page/”, “src/  
default.css/”,  
“src/default.template/”, “src/images/”, “src/images/bodybg.gif/”,  
“src/  
images/boxbg.gif/”, “src/images/greypx.gif/”, “src/images/  
header.jpg/”,  
“src/images/innerbg.gif/”, “src/images/leaves.jpg/”, “src/images/  
tabs.gi  
f/”, “src/index.de.page/”, “src/index.page/”, “src/links.de.page/”,  
“src  
/links.page/”]

Why do all the files get a slash appended and why get files returned  
at all? I imagine that the second command should only return  
directories… at least this was the behaviour before 1.8.6 - same  
session on Windows with Ruby 1.8.5:

irb(main):005:0\> Dir[‘src/ **/** ’]  
=\> [“src/about.de.page”, “src/about.page”, “src/default.css”, “src/  
defau  
lt.template”, “src/images”, “src/index.de.page”, “src/index.page”,  
“src/  
links.de.page”, “src/links.page”, “src/images/bodybg.gif”, “src/images/  
b  
oxbg.gif”, “src/images/greypx.gif”, “src/images/header.jpg”, “src/  
images  
/innerbg.gif”, “src/images/leaves.jpg”, “src/images/tabs.gif”]  
irb(main):006:0\> Dir[‘src/ **/** /’]  
=\> [“src/”, “src/images/”, “src/images/”]

As you can see, this outputs the correct result, at least in my  
understanding.

Has this behaviour already been seen/has anyone an explanation for  
this and does anyone know how to only get directories using Dir.[] in  
ruby 1.8.6 under Windows?

Thanks for helping!

Best regards,  
Thomas

ps. Also tested this with Ruby 1.8.6 unde Mac OSX and there it works  
just fine!

---

<div class="post-metadata">

**Author:** ![tlockney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5e9695/32.png) [@tlockney](https://www.ruby-forum.com/u/tlockney)\
**Post date:** [May 17, 2007, 11:15pm UTC](https://www.ruby-forum.com/t/bug-in-dir-glob-in-1-8-6-on-windows/104425/2 "2007-05-17T23:15:32Z")

</div>

Thomas L. schrieb:

> Has this behaviour already been seen/has anyone an explanation for  
> this and does anyone know how to only get directories using Dir.[] in  
> ruby 1.8.6 under Windows?

C:\Dokumente und Einstellungen\wolfgang\Desktop\>ruby -v  
ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]

C:\Dokumente und Einstellungen\wolfgang\Desktop\>irb  
irb(main):001:0\> Dir[‘dirtest/ **/** ’]  
=\> [“dirtest/dat1.txt”, “dirtest/dat2.txt”, “dirtest/sub1”,  
“dirtest/sub1/sub11”, “dirtest/sub1/sub1/dat1.txt”, “dirtest/sub2”,  
“dirtest/sub2/sub21”, “dirtest/sub2/sub2dat1.txt”]  
irb(main):002:0\> Dir[‘dirtest/ **/** ’].find\_all{|f|File.directory?(f)}  
=\> [“dirtest/sub1”, “dirtest/sub1/sub11”, “dirtest/sub2”,  
“dirtest/sub2/sub21”]

The Problem does not appear using a Ruby 1.9 snapshot under Windows:

C:\Dokumente und Einstellungen\wolfgang\Desktop\>ruby19 -v  
ruby 1.9.0 (2007-05-15 patchlevel 0) [i386-mingw32]

C:\Dokumente und Einstellungen\wolfgang\Desktop\>irb19  
irb(main):001:0\> Dir[‘dirtest/ **/** ’]  
=\> [“dirtest/dat1.txt”, “dirtest/dat2.txt”, “dirtest/sub1”,  
“dirtest/sub1/sub11”, “dirtest/sub1/sub1/dat1.txt”, “dirtest/sub2”,  
“dirtest/sub2/sub21”, “dirtest/sub2/sub2dat1.txt”]  
irb(main):002:0\> Dir[‘dirtest/ **/** /’]  
=\> [“dirtest/”, “dirtest/sub1/”, “dirtest/sub1/sub11/”, “dirtest/sub2/”,  
“dirtest/sub2/sub21/”]

Wolfgang Nádasi-Donner

---

<div class="post-metadata">

**Author:** ![tlockney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5e9695/32.png) [@tlockney](https://www.ruby-forum.com/u/tlockney)\
**Post date:** [May 18, 2007, 7:51am UTC](https://www.ruby-forum.com/t/bug-in-dir-glob-in-1-8-6-on-windows/104425/3 "2007-05-18T07:51:19Z")

</div>

On May 17, 11:16 pm, Wolfgang Nádasi-Donner [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> irb(main):001:0\> Dir[‘dirtest/ **/** ’]  
> =\> [“dirtest/dat1.txt”, “dirtest/dat2.txt”, “dirtest/sub1”,  
> “dirtest/sub1/sub11”, “dirtest/sub1/sub1/dat1.txt”, “dirtest/sub2”,  
> “dirtest/sub2/sub21”, “dirtest/sub2/sub2dat1.txt”]  
> irb(main):002:0\> Dir[‘dirtest/ **/** ’].find\_all{|f|File.directory?(f)}  
> =\> [“dirtest/sub1”, “dirtest/sub1/sub11”, “dirtest/sub2”, “dirtest/sub2/sub21”]

Thanks for this suggestions! I know that I can filter afterwards but I  
need a version which just uses a glob pattern.

Regards,  
Thomas

---

<div class="post-metadata">

**Author:** ![tlockney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5e9695/32.png) [@tlockney](https://www.ruby-forum.com/u/tlockney)\
**Post date:** [May 18, 2007, 10:24am UTC](https://www.ruby-forum.com/t/bug-in-dir-glob-in-1-8-6-on-windows/104425/4 "2007-05-18T10:24:46Z")

</div>

Hi,

At Fri, 18 May 2007 04:35:04 +0900,  
Thomas L. wrote in [ruby-talk:251987]:

> I got a bug report for webgen which appeared when the user change from  
> ruby 1.8.5 to 1.8.6 using the One-Click-Ruby-Installer. Following is  
> an extract from an IRB session under Windows with ruby 1.8.6:

Thank you for the report, fixed now.

> Has this behaviour already been seen/has anyone an explanation for  
> this and does anyone know how to only get directories using Dir.[] in  
> ruby 1.8.6 under Windows?

Windows API FindFirstFile/FindNextFile return the file mode  
together, and Dir#glob about to utilize it to tell if it is a  
directory. The bug is that the info for the first entry,  
i.e. “.”, was always used.

---

<div class="post-metadata">

**Author:** ![tlockney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5e9695/32.png) [@tlockney](https://www.ruby-forum.com/u/tlockney)\
**Post date:** [May 18, 2007, 11:50am UTC](https://www.ruby-forum.com/t/bug-in-dir-glob-in-1-8-6-on-windows/104425/5 "2007-05-18T11:50:54Z")

</div>

On May 18, 10:23 am, Nobuyoshi N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Has this behaviour already been seen/has anyone an explanation for  
> > this and does anyone know how to only get directories using Dir.[] in  
> > ruby 1.8.6 under Windows?
> 
> Windows API FindFirstFile/FindNextFile return the file mode  
> together, and Dir#glob about to utilize it to tell if it is a  
> directory. The bug is that the info for the first entry,  
> i.e. “.”, was always used.

Thanks for the fast reply, the fix and the explanation! I assume that  
this fix will be in the next release of the One-Click-Installer for  
Windows?!

Thomas
