# Load a path (not a file)

**URL:** <https://www.ruby-forum.com/t/load-a-path-not-a-file/160846>\
**Category:** Ruby\
**Created:** [February 20, 2009, 8:18am UTC](https://www.ruby-forum.com/t/load-a-path-not-a-file/160846 "2009-02-20T08:18:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![elioncho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ed8c4c/32.png) [@elioncho](https://www.ruby-forum.com/u/elioncho)\
**Post date:** [February 20, 2009, 8:18am UTC](https://www.ruby-forum.com/t/load-a-path-not-a-file/160846/1 "2009-02-20T08:18:17Z")

</div>

Hello guys,

I need to load a path not a file. I am trying this but it is not working

load RAILS\_ROOT+"/public/users/#{self.login}/lib/"

Can you guys help me,

Thanks

---

<div class="post-metadata">

**Author:** ![elioncho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ed8c4c/32.png) [@elioncho](https://www.ruby-forum.com/u/elioncho)\
**Post date:** [February 20, 2009, 8:28am UTC](https://www.ruby-forum.com/t/load-a-path-not-a-file/160846/2 "2009-02-20T08:28:54Z")

</div>

Alle Friday 20 February 2009, Elias O. ha scritto:

> Hello guys,
> 
> I need to load a path not a file. I am trying this but it is not working
> 
> load RAILS\_ROOT+"/public/users/#{self.login}/lib/"
> 
> Can you guys help me,
> 
> Thanks

What do you mean by “load a path”? A path isn’t a ruby file, so you  
can’t load  
it. If you mean “load all ruby files contained in a directory”, you can  
do  
something like this:

dir = RAILS\_ROOT+"/public/users/#{self.login}/lib/"  
Dir.entries(d).each do |f|  
load File.join(d, f) if file.match(/.rb$/)  
end

Stefano

---

<div class="post-metadata">

**Author:** ![elioncho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ed8c4c/32.png) [@elioncho](https://www.ruby-forum.com/u/elioncho)\
**Post date:** [February 20, 2009, 9:06am UTC](https://www.ruby-forum.com/t/load-a-path-not-a-file/160846/3 "2009-02-20T09:06:25Z")

</div>

On Fri, 20 Feb 2009 16:26:33 +0900  
In article [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[Re: load a path (not a file)]  
Stefano C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > I need to load a path not a file. I am trying this but it is not working
> > 
> > load RAILS\_ROOT+“/public/users/#{self.login}/lib/”

It is NOT recommended to put ruby files under Rails “public” directory  
because their files can be shown by any web browsers in the world.

> dir = RAILS\_ROOT+“/public/users/#{self.login}/lib/”  
> Dir.entries(d).each do |f|  
> load File.join(d, f) if file.match(/.rb$/)  
> end

Dir.[] or Dir.glob is easier.

Dir.glob(“#{RAILS\_ROOT}/public/users/#{self.login}/lib/\*.rb”).each { |f|  
load(f) }

---

<div class="post-metadata">

**Author:** ![elioncho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ed8c4c/32.png) [@elioncho](https://www.ruby-forum.com/u/elioncho)\
**Post date:** [February 20, 2009, 9:14am UTC](https://www.ruby-forum.com/t/load-a-path-not-a-file/160846/4 "2009-02-20T09:14:02Z")

</div>

Thanks guys,

That was very helpful and just what I wanted.

I will try to move the files to another folder for security then.

ElÃ­as
