# Ruby & Windows and Dir() EINVAL bug?

**URL:** <https://www.ruby-forum.com/t/ruby-windows-and-dir-einval-bug/157232>\
**Category:** Ruby\
**Created:** [January 8, 2009, 6:45pm UTC](https://www.ruby-forum.com/t/ruby-windows-and-dir-einval-bug/157232 "2009-01-08T18:45:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 8, 2009, 6:45pm UTC](https://www.ruby-forum.com/t/ruby-windows-and-dir-einval-bug/157232/1 "2009-01-08T18:45:36Z")

</div>

Hello,

I am using Ruby 1.8.6-26 on Windows. I have this little test script:

* * *

system(“dir x:\.\Radeloff\Projects\DATA\NLCD\_2001\landcover  
\nlcd\_fg11”)

serverDirName = “x:/./Radeloff/Projects/DATA\_NLCD\_2001/landcover/  
nlcd\_fg11”

Dir.new(serverDirName).each do | dirEntry |  
if inHere.nil?  
print “Found the directory #{serverDirName} just fine!\n”  
inHere = true  
end  
end

* * *

The first line succeeds. The Dir.new() line bombs out with  
Errno::EINVAL.Note that the Dir.new() code was taken out of a working  
script that works for millions of files and directories except this  
one. The funky “x:/./…” stuff works all the time. I have looked at  
file permissions on the directory in question and it matches other  
directories in the same place that work fine.

Can anyone tell me what could be wrong here? Could this be a Ruby bug?

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 8, 2009, 7:36pm UTC](https://www.ruby-forum.com/t/ruby-windows-and-dir-einval-bug/157232/2 "2009-01-08T19:36:10Z")

</div>

On Jan 8, 10:44 am, removed\_email\_address@domain.invalid wrote:

> script that works for millions of files and directories except this  
> one. The funky “x:/./…” stuff works all the time. I have looked at  
> file permissions on the directory in question and it matches other  
> directories in the same place that work fine.
> 
> Can anyone tell me what could be wrong here? Could this be a Ruby bug?

It’s not being caused by the ‘.’. I just tried it:

irb(main):002:0\> Dir.new(“C:/staging”).each{ |f| p f }  
“.”  
“…”  
“ptools-1.1.6”  
“windows-pr-0.9.8”  
“windows-pr-0.9.8.zip”  
=\> #Dir:0x2e37ea0  
irb(main):003:0\> Dir.new(“C:/./staging”).each{ |f| p f }  
“.”  
“…”  
“ptools-1.1.6”  
“windows-pr-0.9.8”  
“windows-pr-0.9.8.zip”  
=\> #Dir:0x2e32874

BTW, you can shortcut Dir.new(dir).each with Dir.foreach(dir),  
although I don’t think it will solve your problem.

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 8, 2009, 9:33pm UTC](https://www.ruby-forum.com/t/ruby-windows-and-dir-einval-bug/157232/3 "2009-01-08T21:33:55Z")

</div>

> system(“dir x:\.\Radeloff\Projects\DATA\NLCD\_2001\landcover  
> \nlcd\_fg11”)
> 
> serverDirName = “x:/./Radeloff/Projects/DATA\_NLCD\_2001/landcover/  
> nlcd\_fg11”

was the error a typo? should it have been:

serverDirName = “x:/./Radeloff/Projects/DATA/NLCD\_2001/landcover/  
nlcd\_fg11”

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 8, 2009, 9:45pm UTC](https://www.ruby-forum.com/t/ruby-windows-and-dir-einval-bug/157232/4 "2009-01-08T21:45:47Z")

</div>

On Jan 8, 2:33 pm, Greg H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> –  
> Posted viahttp://www.ruby-forum.com/.

Arg. Yes and no. My test program did have a typo. Once fixed the test  
program works.

Unfortunately the actual script it was taken from is typoless and I’m  
still at a loss for why it crashes. I’m not specifying this directory.  
Its being built from the Dir above it. I have so many files that it  
takes days to get to this directory before the crash. Thus I’m having  
trouble debugging it. (I also don’t think this is the only directory  
it crashes on like this but I haven’t tracked it carefully to know)

The only thing I forgot to mention is that this is running on Server  
2003 64-bit.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 9, 2009, 12:55am UTC](https://www.ruby-forum.com/t/ruby-windows-and-dir-einval-bug/157232/5 "2009-01-09T00:55:19Z")

</div>

removed\_email\_address@domain.invalid wrote:

> > Posted viahttp://www.ruby-forum.com/.
> 
> The only thing I forgot to mention is that this is running on Server  
> 2003 64-bit.

Try wrapping the offending code in a begin/rescue and see if you can  
glean anything from the backtrace.

begin  
your\_code  
rescue Errno::EINVAL =\> err  
log(file)  
log(err.backtrace.join("\n")  
raise  
end

Regards,

Dan
