[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

NEWBIE) Reading folders from a directory into an array

rbr

10/10/2006 3:36:00 PM

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

3 Answers

eden li

10/10/2006 4:10:00 PM

0

Dir['/path/*'].select { |f| File.directory? f }.each do |directory|
# do your thing
end

Read more at http://www.rubycentral.com/book/ref_...


rbr

10/10/2006 4:57:00 PM

0

Thank you! That is great!

rbr

eden li wrote:
> Dir['/path/*'].select { |f| File.directory? f }.each do |directory|
> # do your thing
> end
>
> Read more at http://www.rubycentral.com/book/ref_...

Trans

10/10/2006 11:43:00 PM

0


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.