[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

difference in file.join between Linux, win32?

Roger Pack

1/31/2009 6:01:00 AM

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
--
Posted via http://www.ruby-....

5 Answers

Tony L.

1/31/2009 7:34:00 PM

0

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

Roger Pack 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.

Jarmo Pertman

1/31/2009 7:42:00 PM

0

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

Luis Lavena

1/31/2009 8:43:00 PM

0

On Jan 31, 5:41 pm, Jarmo Pertman <jarm...@gmail.com> 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

--
Luis Lavena

Roger Pack

1/31/2009 9:47:00 PM

0


> 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
--
Posted via http://www.ruby-....

Suraj Kurapati

2/1/2009 2:44:00 AM

0

Roger Pack 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.
--
Posted via http://www.ruby-....