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
on 2009-01-31 03:58
on 2009-01-31 21:35
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.
on 2009-01-31 21:41
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 2009-01-31 22:45
On Jan 31, 5:41 pm, Jarmo P. <firstname.lastname@example.org> 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
on 2009-01-31 23:47
> 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
on 2009-02-01 04:44
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.