Difference in file.join between Linux, win32?

question:

if I run some code within the following directory structure
./substruct_start_and_bootstrap_if_necessary.rb
./substruct [directory]
/config
boot.rb

this code is within substruct_start_and_bootstrap_if_necessary.rb [and I
run it from the directory that file is in]:

Dir.chdir ‘substruct’
puts File.dirname(FILE)

in Linux
=> /home/rdp/dev/ruby-benchmark-suite/rails

in windows
=> .

I assume this is a windows bug [if you do a chdir then File.dirname is
off after that point].
?

However, in Linux
Dir.chdir ‘/’
puts File.dirname(FILE)

results in ‘.’ [which is wrong at that point], too.

Thoughts?
-=r

Not sure how this question is related to File.join().

Roger P. wrote:

Dir.chdir ‘substruct’
puts File.dirname(FILE)

What do you expect here?
For my understanding the Dir.chdir()
does not have an impact on the contents
of the variable FILE.

I see - on both Linux and Windows - the
‘.’ only when I am in IRB.

t.

Strange, it worked for me correctly under Windows XP when starting
script right with .rb file itself, like
D:\Projects\Ruby>blah.rb
D:/Projects/Ruby

But, when starting with ruby.exe:
D:\Projects\Ruby>ruby blah.rb
.

I don’t know why it works like this, but you could make it working
correctly somehow like this:
working_dir = File.expand_path(File.dirname(FILE))
Dir.chdir ‘substruct’
puts dir

Jarmo

Roger P. wrote:

in windows
=> .

On Jan 31, 5:41 pm, Jarmo P. [email protected] wrote:

Strange, it worked for me correctly under Windows XP when starting
script right with .rb file itself, like
D:\Projects\Ruby>blah.rb
D:/Projects/Ruby

But, when starting with ruby.exe:
D:\Projects\Ruby>ruby blah.rb

That’s because you didn’t provide the path to blah.rb

Luis@KEORE (D:\Users\Luis\Desktop)
$ type blah.rb
puts File.dirname(FILE)

Luis@KEORE (D:\Users\Luis\Desktop)
$ ruby blah.rb
.

Luis@KEORE (D:\Users\Luis\Desktop)
$ ruby d:\Users\Luis\Desktop\blah.rb
d:/Users/Luis/Desktop

Roger P. wrote:

on windows:

C:\dev\test>ruby in_root.rb
./config/boot

on linux:

$ ruby in_root.rb
/home/rdp/dev/test/subdir/config/boot

Is this difference expected?

No, it is suprising (principle of least surprise) that, depending on
the operating system, FILE would be a absolute or relative path.

Which version of Ruby does this occur with? Can you try with 1.9.1 once
the Windows one-click installer is released?

We should definitely file a bug report about this.

That’s because you didn’t provide the path to blah.rb

I’m ok with it working that way–the only weirdness is that, with these
files:

in_root.rb:

Dir.chdir ‘subdir’
require ‘in_subdir’

subdir/
in_subdir.rb:
puts File.join(File.dirname(FILE), ‘config’, ‘boot’)

on windows:

C:\dev\test>ruby in_root.rb
./config/boot

on linux:

$ ruby in_root.rb
/home/rdp/dev/test/subdir/config/boot

Is this difference expected?

Thanks!
-=r