How to get directory content?

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

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!
:slight_smile:

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!
:slight_smile:

hi shai, thanks it is exactly what i want :slight_smile:

meanwhile i find Dir.entries("#{RAILS_ROOT}/app/controllers/")

but i get controllers filenames, like admin_controller.rb