(NEWBIE) Reading folders from a directory into an array

I am a newbie looking to use Ruby to create a maintenance script for my
MySQL database server. There are several things I would need to do.
First and foremost, I would like to read in the folder names from the
MySQL data directory to an array then use this array to perform
specified maintenance and backup procedures on the databases.
Currently, I read from a flat text file that needs to be updated every
time a db is added or removed from the server. I would like to
eliminate this tedious task.

Sorry for the simplistic question. This is my first foray into a
scripting language. The limit of my knowledge comes from a couple of
online tutorials.

Thank you in advance!

rbr

Dir[‘/path/*’].select { |f| File.directory? f }.each do |directory|

do your thing

end

Read more at http://www.rubycentral.com/book/ref_c_dir.html

eden li wrote:

Dir[’/path/*’].select { |f| File.directory? f }.each do |directory|

do your thing

end

Dir[] is an alias for Dir.glob, just so you know. Possibly you can do
without the File.directory? clause by appending an additiona slash:

Dir.glob(’/path/*/’).each do |directory|
# …
end

T.

Thank you! That is great!

rbr