How can I tell what directory the current file being executed is in?
This is not necessarily the same directory as returned by “Dir.pwd”.
I have “/home/seasft/dev/global” in my path. Inside this directory, there
is:
entity.rb
entity/staff.rb
entity/project.rb
entity/section.rb
…
I want entity.rb to load all the .rb files inside the “entity” directory.
I’m trying this right now:
File.find(‘entity’) do |f|
load f if f =~ /.rb$/
end
But, that uses the current working directory, rather than the directory
that entity.rb is located in. I can’t figure out how to determine what
directory entity.rb is in, and I’d rather not have to hardcode the path
because I have two copies of the system running in different places.
Hi,
How can I tell what directory the current file being executed is in?
File.expand_path(File.dirname(FILE))
I want entity.rb to load all the .rb files inside the “entity” directory.
I’m trying this right now:
File.find(‘entity’) do |f|
load f if f =~ /.rb$/
end
Dir.glob(File.dirname(FILE)+“/*.rb”) do |f|
load f
end
Or
Dir.foreach(File.dirname(FILE)) do |f|
load f if /.rb$/ =~ f
end
···
At Wed, 18 Sep 2002 01:28:55 +0900, Philip Mak wrote:
–
Nobu Nakada
absolute_filename = File.expand_path(FILE, Dir.getwd)
full_path = File.dirname(absolute_filename)
Find.find(File.join(full_path, ‘entity’)) do |f|
load f if f =~ /.rb$/
end
···
On Wed, Sep 18, 2002 at 01:28:55AM +0900, Philip Mak wrote:
File.find(‘entity’) do |f|
load f if f =~ /.rb$/
end