From: "Mehr, Assaph (Assaph)" Date: 2004-04-30T08:59:37+09:00 Subject: Re: File.expand_path(__FILE__) > I'm having a problem with File.expand_path(__FILE__) after a chdir. > Looks like a bug in Ruby to me. If someone can tell me what I'm doing > wrong, I'd be grateful. > Here's the reduction: > [ryan@kursk 15:26:38 ~]$ cat tmp/demo-problem.rb > puts "starting working directory: " + Dir.getwd > puts "expand_path: " + File.expand_path(__FILE__) > puts "about to change to dirname of __FILE__: " + __FILE__ > Dir.chdir(File.dirname(__FILE__)) > puts "new working directory: " + Dir.getwd > puts "expand_path: " + File.expand_path(__FILE__) IIUC, It's actually behaving properly: Most dir references are relative by default in ruby. Thus, __FILE__ in your example is just 'temp/demo.rb' and not the absolute path. Add a call to Dir.getwd at the end and you'll see you are in the right path. I usually define at the start of my apps a constant: $APP_PATH = File.expand_path(File.dirname(__FILE__)) Usually closely followed by: $LOAD_PATH << $APP_PATH