ruby - Directory walk call method when directory is reached -
trying write script search through directory , sub-directories specific files. know how directory or directories come call method.
this have tried , failed:
def display_directory(path) list = dir[path+'/*'] return if list.length == 0 list.each |f| if file.directory? f #is directory? if file.directory?('config') puts "this config folder" end printf "%-50s %s\n", f, "is directory:".upcase.rjust(25) else printf "%-50s %s\n", f, "is not directory:".upcase.rjust(25) end end end start = file.join("**") puts "processing directory\n\n".upcase.center(30) display_directory start
this want happen.
app app/controllers app/helpers app/mailers app/models app/models/bugzilla app/models/security app/views app/views/auth app/views/calendar app/views/layouts app/views/step app/views/step_mailer app/views/suggestion app/views/suggestion_mailer app/views/task app/views/user bin -------------------------------------- config <----------(call method foo) config/environments config/initializers config/locales -------------------------------------- db db/bugzilla db/migrate db/security lib lib/tasks log public public/images public/javascripts public/stylesheets script script/performance script/process -------------------------- test <---------(call method foobar) test/fixtures test/fixtures/mailer test/functional test/integration test/performance test/unit -------------------------- vendor vendor/plugins
instead
if file.directory?('config')
try
if f.path.include?('config')
but work every directory have config on name. can put larger substring make better match.
also, idiomatic in ruby use do..end
multiline blocks , {..}
single line.
Comments
Post a Comment