# How to get directory content?

**URL:** <https://www.ruby-forum.com/t/how-to-get-directory-content/112094>\
**Category:** Rails\
**Created:** [August 15, 2007, 10:59am UTC](https://www.ruby-forum.com/t/how-to-get-directory-content/112094 "2007-08-15T10:59:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sineserz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@sineserz](https://www.ruby-forum.com/u/sineserz)\
**Post date:** [August 15, 2007, 10:59am UTC](https://www.ruby-forum.com/t/how-to-get-directory-content/112094/1 "2007-08-15T10:59:11Z")

</div>

hi,

I am trying to collect all controllers names in application.  
how to get directory contents under /app/controllers/

any1 have any idea

I look up the File & FileUtils classes, but cant find anything

thanks

serz

---

<div class="post-metadata">

**Author:** ![sineserz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@sineserz](https://www.ruby-forum.com/u/sineserz)\
**Post date:** [August 15, 2007, 12:18pm UTC](https://www.ruby-forum.com/t/how-to-get-directory-content/112094/2 "2007-08-15T12:18:22Z")

</div>

def find\_controller\_names  
a = []  
Find.find( RAILS\_ROOT + ‘/app/controllers’ ) do |file\_name|  
if /.rb$/ =~ file\_name  
a \<\< File.basename(file\_name).gsub(’.rb’, ‘’).camelcase  
end  
end  
render\_text a.inspect  
end

if you run find\_controller\_names, you’ll get something like  
[“Application”, “SomeController”, “OtherController”]

hope it helps!  
🙂

---

<div class="post-metadata">

**Author:** ![sineserz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@sineserz](https://www.ruby-forum.com/u/sineserz)\
**Post date:** [August 15, 2007, 12:26pm UTC](https://www.ruby-forum.com/t/how-to-get-directory-content/112094/3 "2007-08-15T12:26:21Z")

</div>

Shai R. wrote:

> def find\_controller\_names  
> a = []  
> Find.find( RAILS\_ROOT + ‘/app/controllers’ ) do |file\_name|  
> if /.rb$/ =~ file\_name  
> a \<\< File.basename(file\_name).gsub(’.rb’, ‘’).camelcase  
> end  
> end  
> render\_text a.inspect  
> end
> 
> if you run find\_controller\_names, you’ll get something like  
> [“Application”, “SomeController”, “OtherController”]
> 
> hope it helps!  
> 🙂

hi shai, thanks it is exactly what i want 🙂

meanwhile i find Dir.entries("#{RAILS\_ROOT}/app/controllers/")

but i get controllers filenames, like admin\_controller.rb
