(NEWBIE) Reading folders from a directory into an array

R

rbr

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
 
T

Trans

eden said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,214
Messages
2,571,112
Members
47,705
Latest member
noname22

Latest Threads

Top