Check directory for files, retrieve first file
Posted
by Lowgain
on Stack Overflow
See other posts from Stack Overflow
or by Lowgain
Published on 2010-05-09T20:00:03Z
Indexed on
2010/05/09
20:28 UTC
Read the original article
Hit count: 176
I'm writing a small ruby daemon that I am hoping will do the following:
- Check if a specific directory has files (in this case, .yml files)
- If so, take the first file (numerically sorted preferrably), and parse into a hash
- Do a 'yield', with this hash as the argument
What I have right now is like:
loop do
get_next_in_queue { |s| THINGS }
end
def get_next_in_queue
queue_dir = Dir[File.dirname(__FILE__)+'/../queue']
info = YAML::load_file(queue_dir[0]) #not sure if this works or not
yield info
end
I'd like to make the yield conditional if possible, so it only happens if a file is actually found. Thanks!
© Stack Overflow or respective owner