I''ve been trying to find the "right" way to do this and I''m now appealing to the Rails masses. :) I want to list all the directory names in a specific location and have just the directory names appear in a dropdown control for the user. The Dir.entries("somepath") includes the "." and ".." folders plus all files and folders. The Dir.glob() is hard for me to work with. I''m not familiar with that type of search. Part of my problem is that it seems the best fit but I''m not sure how to make it work with any given directory path. It seems to work off the current one and I feared changing the current one and having odd bugs when concurrency issues arrise when the page is viewed more frequently and different base directories are being searched. So, what is the right rails way to do this? Thanks, Mark E. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060726/6fe7ae31/attachment.html
Ezra Zygmuntowicz
2006-Jul-26 06:51 UTC
[Rails] List directory names in a dropdown control?
On Jul 25, 2006, at 9:07 PM, Mark Spamfre wrote:> I''ve been trying to find the "right" way to do this and I''m now > appealing to the Rails masses. :) > > I want to list all the directory names in a specific location and > have just the directory names appear in a dropdown control for the > user. > > The Dir.entries("somepath") includes the "." and ".." folders plus > all files and folders. > The Dir.glob() is hard for me to work with. I''m not familiar with > that type of search. Part of my problem is that it seems the best > fit but I''m not sure how to make it work with any given directory > path. It seems to work off the current one and I feared changing > the current one and having odd bugs when concurrency issues arrise > when the page is viewed more frequently and different base > directories are being searched. > > So, what is the right rails way to do this? > > Thanks, > Mark E.Mark- You can use the [] bracket form of Dir to get what you want i think. You can just pass it the full path to the dir you want. Or use RAILS_ROOT to refer to the root of your rails app dir. Try something like this: # aray of all the files in your apps public/files dir. does not descend into subdirectories. files = Dir["#{RAILS_ROOT}/public/files/*"] # aray of all the files in your apps public/files dir. this one does descend into subdirectories. files = Dir["#{RAILS_ROOT}/public/files/**/*"] Cheers- -Ezra