File.exist? mystery

Hi there,

The following seems very odd to me (file doesn’t exist after I created
it!). Is there something I did wrong?

irb(main):056:0* File.open(’/tmp/test.txt’, ‘w’) { |f| f.write(‘hello’)
}
=> 5
irb(main):057:0> File.exist?(’/tmp/test.txt’)
=> true
irb(main):058:0> File.expand_path(’/tmp/test.txt’)
=> “D:/tmp/test.txt”
irb(main):059:0> File.exist?(‘D:/tmp/test.txt’)
=> false
irb(main):060:0> File.exist?(‘D:\tmp\test.txt’)
=> false

I am using WindowsXP, and
jruby 1.4.0 (ruby 1.8.7 patchlevel 174) (2009-11-02 69fbfa3) (Java
HotSpot™ Client VM 1.6.0_16) [x86-java]

Thanks,
-Z

Hi,

I think this is a JRuby bug. Take a look:
http://jira.codehaus.org/browse/JRUBY-2564

Basically, JRuby treats ‘/’ at the beginning of the file name a bit
differently than MRI. JRuby treats it as relative path, to the current
directory. MRI treats it as absolute path (to the current drive).

Thanks,
–Vladimir

On Thu, Dec 10, 2009 at 1:50 PM, Zemian D. [email protected]
wrote:

irb(main):058:0> File.expand_path(‘/tmp/test.txt’)
Thanks,


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email