# Ruby 1.8.0 bugs on Dir

**URL:** <https://rubytalk.org/t/ruby-1-8-0-bugs-on-dir/9629>\
**Category:** ruby-talk\
**Created:** [10 January 2004 09:11 UTC](https://rubytalk.org/t/ruby-1-8-0-bugs-on-dir/9629 "2004-01-10T09:11:38Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gga](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@gga](https://rubytalk.org/u/gga)\
**Post date:** [10 January 2004 09:11 UTC](https://rubytalk.org/t/ruby-1-8-0-bugs-on-dir/9629/1 "2004-01-10T09:11:38Z")

</div>

Okay, two separate bugs. One probably on all platforms and one more serious  
one only on mswindows.

BUG 1 (MS only)

> **···**
>
> =====  
> Using the version with the automatic installer on windows and cygwin, too.
> 
> $ C:/ruby/bin/ruby -v  
> ruby 1.8.0 (2003-08-04) [i386-mswin32]  
> $ ruby -v  
> ruby 1.8.0 (2003-08-04) [i386-cygwin]
> 
> A simple script that returns the directory contents of a dir.
> 
> #!/usr/bin/ruby
> 
> puts ARGV[0]
> 
> Dir.foreach(ARGV[0]) { |i|  
> print i, " "  
> }
> 
> $ bug.fb C:  
> will instead open and list the current directory on ruby mswin32, instead of C:
> 
> $ bug.fb C:/  
> works fine.
> 
> Both work properly opening under ruby cygwin.
> 
> # BUG 2
> 
> #!/usr/bin/ruby
> 
> puts ARGV[0]
> 
> Dir.open(ARGV[0]) { |i|  
> print i, " "  
> }
> 
> will print:  
> C:\ruby\learningGGA\>bug2.rb C:  
> C:  
> #Dir:0x2847fa8
> 
> on any of my two ruby versions. This is inconsistent with what ri docs say it  
> should do.

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [10 January 2004 09:47 UTC](https://rubytalk.org/t/ruby-1-8-0-bugs-on-dir/9629/2 "2004-01-10T09:47:27Z")

</div>

Hi,

> # BUG 1 (MS only)
> 
> $ bug.fb C:  
> will instead open and list the current directory on ruby mswin32, instead of C:

“The current directory on ruby mswin32” is in C:? So it just  
works as like as “dir C:” does.

What do you expect?

> # BUG 2
> 
> Dir.open(ARGV[0]) { |i|  
> print i, " "  
> }
> 
> will print:  
> C:\ruby\learningGGA\>bug2.rb C:  
> C:  
> #Dir:0x2847fa8
> 
> on any of my two ruby versions. This is inconsistent with what ri docs say it  
> should do.

$ ri Dir.open  
-------------------------------------------------------------- Dir::open  
Dir.open( string ) =\> aDir  
Dir.open( string ) {| aDir | block } =\> anObject

> **···**
>
> ## At Sat, 10 Jan 2004 18:11:38 +0900, GGarramuno wrote:
> 
> ```
> With no block, +open+ is a synonym for +Dir::new+. If a block is
> present, it is passed _aDir_ as a parameter. The directory is
> closed at the end of the block, and +Dir::open+ returns the value
> of the block.
> 
> ```
> 
> What and how inconsistent do you feel?
> 
> –  
> Nobu Nakada

---

<div class="post-metadata">

**Author:** ![gga](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@gga](https://rubytalk.org/u/gga)\
**Post date:** [10 January 2004 18:36 UTC](https://rubytalk.org/t/ruby-1-8-0-bugs-on-dir/9629/3 "2004-01-10T18:36:41Z")

</div>

> “The current directory on ruby mswin32” is in C:? So it just  
> works as like as “dir C:” does.
> 
> What do you expect?

The command should indeed work as the msdos dir command, listing the contents  
of the C: drive. Yet, it does not.  
Passing the String “C:” to it lists not the contents of the C: drive but the  
contents of the current directory in my mswin32 version of ruby. Only if I  
pass “C:/” will it list the right directory.  
The same version of ruby,on cygwin, works as it should, listing the contents of  
C: when “C:” or “C:/” is passed to it.

> What and how inconsistent do you feel?

Oops, no inconsistency. My bad.  
It passes the DIR object to the block. I expected it to be a File object, just  
as foreach but closing the object after, as that seemed to be much more useful  
and logical.

---

<div class="post-metadata">

**Author:** ![Austin\_Ziegler2](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@Austin\_Ziegler2](https://rubytalk.org/u/Austin_Ziegler2)\
**Post date:** [10 January 2004 21:50 UTC](https://rubytalk.org/t/ruby-1-8-0-bugs-on-dir/9629/4 "2004-01-10T21:50:42Z")

</div>

It does:

C:\home\>dir c:  
Volume in drive C is Portable

Directory of C:\home

C:\home\>dir c:  
Volume in drive C is Portable

Directory of c:\

-austin

> **···**
>
> On Sun, 11 Jan 2004 03:36:41 +0900, GGarramuno wrote:
> 
> > > “The current directory on ruby mswin32” is in C:? So it just works as  
> > > like as “dir C:” does.
> > > 
> > > What do you expect?  
> > > The command should indeed work as the msdos dir command, listing the  
> > > contents of the C: drive. Yet, it does not.  
> > > Passing the String “C:” to it lists not the contents of the C: drive but  
> > > the contents of the current directory in my mswin32 version of ruby.  
> > > Only if I pass “C:/” will it list the right directory.  
> > > The same version of ruby,on cygwin, works as it should, listing the  
> > > contents of C: when “C:” or “C:/” is passed to it.
> 
> –  
> austin ziegler \* austin@halostatue.ca \* Toronto, ON, Canada  
> software designer \* pragmatic programmer \* 2004.01.10  
> \* 16.48.43

---

<div class="post-metadata">

**Author:** ![John\_W\_Kennedy](https://avatars.discourse-cdn.com/v4/letter/j/c77e96/32.png) [@John\_W\_Kennedy](https://rubytalk.org/u/John_W_Kennedy)\
**Post date:** [11 January 2004 02:56 UTC](https://rubytalk.org/t/ruby-1-8-0-bugs-on-dir/9629/5 "2004-01-11T02:56:39Z")

</div>

GGarramuno wrote:

> The command should indeed work as the msdos dir command, listing the contents  
> of the C: drive.

It _does_ work as the MS-DOS dir command does: it lists the contents of  
the current directory of the C: drive. The MS-DOS dir command has  
worked that way for over twenty years.

> The same version of ruby,on cygwin, works as it should, listing the contents of  
> C: when “C:” or “C:/” is passed to it.

MS-DOS and Windows (and OS/2) have the concept of a number of drives,  
each one of which has a current directory of its own. Unix lacks this  
concept. On a real Unix system, each physical drive (or partition)  
after the boot drive is mapped onto a subdirectory. Programs see only  
one single directory tree, with only one current directory, and have no  
concept of drives at all.

Since Cygwin is,by definition, a fake Unix, it has to follow the same  
rules as Unix. “C:” in Cygwin is just an alias to a Cygwin subdirectory  
named /cygdrive/c. So “ls c:” in Cygwin does the same as “ls  
/cygdrive/c”, and Ruby for Cygwin works the same way.

In short, Ruby is doing the correct MS-DOS thing in its Windows version  
and the correct Unix thing in its Unix versions, including Cygwin.

> **···**
>
> –  
> John W. Kennedy  
> “But now is a new thing which is very old–  
> that the rich make themselves richer and not poorer,  
> which is the true Gospel, for the poor’s sake.”  
> – Charles Williams. “Judgement at Chelmsford”

---

<div class="post-metadata">

**Author:** ![gga](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@gga](https://rubytalk.org/u/gga)\
**Post date:** [11 January 2004 02:36 UTC](https://rubytalk.org/t/ruby-1-8-0-bugs-on-dir/9629/6 "2004-01-11T02:36:39Z")

</div>

Austin Ziegler [austin@halostatue.ca](mailto:austin@halostatue.ca) wrote in message news:[2004110165022.739336@PADD](mailto:2004110165022.739336@PADD)…

> It does:
> 
> C:\home\>dir c:  
> Volume in drive C is Portable
> 
> Directory of C:\home
> 
> C:\home\>dir c:  
> Volume in drive C is Portable
> 
> Directory of c:\
> 
> -austin

Err… That can’t be, as I never print anything like Volume in my code.  
You seem to be running the msdos dir command, perhaps?

This is what I get with the code posted as bug.rb on windows XP:

C:\ruby\learningGGA\>bug.rb C:  
C:  
… … whichrb.rb CVSROOT dist FOX\_tut1.rb copy.png

C:\ruby\learningGGA\>bug.rb C:/  
C:/  
MSDOS.SYS AUTOEXEC.BAK pagefile.sys AUTOEXEC.DOS CONFIG.DOS CONFIG.BAK CONFIG.SYS

---

<div class="post-metadata">

**Author:** ![gga](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@gga](https://rubytalk.org/u/gga)\
**Post date:** [11 January 2004 02:52 UTC](https://rubytalk.org/t/ruby-1-8-0-bugs-on-dir/9629/7 "2004-01-11T02:52:11Z")

</div>

> It does:
> 
> C:\home\>dir c:  
> Volume in drive C is Portable
> 
> Directory of C:\home
> 
> C:\home\>dir c:  
> Volume in drive C is Portable
> 
> Directory of c:\
> 
> -austin

Err… Never mind. Nothing to do with ruby.  
It seems to be an OS issue with cmd.exe with the machine I am on or  
the installed patch of XP (It isn’t my personal box) or something  
worse like a virus or trojan.  
I am getting the same absolutely weird behavior with a similar Perl  
script and with the MSDOS built-in dir command! Yikes!

---

<div class="post-metadata">

**Author:** ![Rich\_Kilmer](https://avatars.discourse-cdn.com/v4/letter/r/85f322/32.png) [@Rich\_Kilmer](https://rubytalk.org/u/Rich_Kilmer)\
**Post date:** [11 January 2004 02:56 UTC](https://rubytalk.org/t/ruby-1-8-0-bugs-on-dir/9629/8 "2004-01-11T02:56:47Z")

</div>

> Austin Ziegler [austin@halostatue.ca](mailto:austin@halostatue.ca) wrote in message  
> news:[2004110165022.739336@PADD](mailto:2004110165022.739336@PADD)…
> 
> > It does:
> > 
> > C:\home\>dir c:  
> > Volume in drive C is Portable
> > 
> > Directory of C:\home
> > 
> > C:\home\>dir c:  
> > Volume in drive C is Portable
> > 
> > Directory of c:\
> > 
> > -austin
> 
> Err… That can’t be, as I never print anything like Volume in my code.  
> You seem to be running the msdos dir command, perhaps?
> 
> This is what I get with the code posted as bug.rb on windows XP:
> 
> C:\ruby\learningGGA\>bug.rb C:  
> C:  
> … … whichrb.rb CVSROOT dist FOX\_tut1.rb copy.png
> 
> C:\ruby\learningGGA\>bug.rb C:/  
> C:/  
> MSDOS.SYS AUTOEXEC.BAK pagefile.sys AUTOEXEC.DOS CONFIG.DOS CONFIG.BAK  
> CONFIG.SYS

Right. On DOS/Win32 if you list the directory : it lists the  
contents of the current directory on drive and if you pass in  
:\ it lists the root directory on drive . That is what  
you are getting…

In the first example:

bug.rb C:

you are getting a list of the current directory on drive C and

bug.rb C:/

Getting a list of the root directory on drive C.

-rich

> **···**
>
> On Jan 10, 2004, at 9:36 PM, GGarramuno wrote:
> 
> >

---

<div class="post-metadata">

**Author:** ![Ian\_Hobson1](https://avatars.discourse-cdn.com/v4/letter/i/54ee81/32.png) [@Ian\_Hobson1](https://rubytalk.org/u/Ian_Hobson1)\
**Post date:** [11 January 2004 12:56 UTC](https://rubytalk.org/t/ruby-1-8-0-bugs-on-dir/9629/9 "2004-01-11T12:56:39Z")

</div>

> Austin Ziegler [austin@halostatue.ca](mailto:austin@halostatue.ca) wrote in message news:\<200411  
> 0165022.739336@PADD\>…
> 
> > It does:
> > 
> > C:\home\>dir c:  
> > Volume in drive C is Portable
> > 
> > Directory of C:\home
> > 
> > C:\home\>dir c:  
> > Volume in drive C is Portable
> > 
> > Directory of c:\
> > 
> > -austin
> 
> Err… That can’t be, as I never print anything like Volume in my code.  
> You seem to be running the msdos dir command, perhaps?
> 
> This is what I get with the code posted as bug.rb on windows XP:

You will find that the MS Dir command will also behaves this way.

> C:\ruby\learningGGA\>bug.rb C:  
> C:  
> . .. whichrb.rb CVSROOT dist FOX\_tut1.rb copy.png

This is a listing of the CURRENT directory on C: as you asked for.

> C:\ruby\learningGGA\>bug.rb C:/  
> C:/  
> MSDOS.SYS AUTOEXEC.BAK pagefile.sys AUTOEXEC.DOS  
> CONFIG.DOS CONFIG.BAK CONFIG.SYS  
> This is a listing of the root directory on C: as you asked for,

It is behaving as it should…(and as msdos dir does).

Having change to /program files on my C: drive, and swapped back to D:

D:\temp\>dir c:  
Volume in drive C has no label.  
Volume Serial Number is FC35-A3C2

Directory of c:\

04/12/2003 10:02 642 scl.dat  
29/12/2003 12:16 6,314 ZinioInstall.txt  
04/11/2003 09:49 Documents and Settings  
04/11/2003 09:50 Program Files  
06/11/2003 14:49 WINNT  
2 File(s) 6,956 bytes  
3 Dir(s) 2,117,074,944 bytes free

D:\temp\>dir c:  
Volume in drive C has no label.  
Volume Serial Number is FC35-A3C2

Directory of C:\Program Files

04/11/2003 09:50 .  
04/11/2003 09:50 ..  
04/11/2003 09:50 Common Files  
04/11/2003 10:00 Windows NT  
big snip for space reasons…  
D:\temp\>dir c:

Regards

Ian

> **···**
>
> ## In message [af53b0ba.0401101833.6d574150@posting.google.com](mailto:af53b0ba.0401101833.6d574150@posting.google.com), GGarramuno [GGarramuno@aol.com](mailto:GGarramuno@aol.com) writes
> 
> Ian - posting to a Newsgroup. Please remove everything to reply.
