Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Best way to test if a directory is empty
Peter Marks
11/9/2007 6:54:00 AM
I see this question was asked a while back
(
http://www.ruby-...
t...), but I'm having trouble
implementing any of the solutions. I have tried:
if Dir["#{RAILS_ROOT}/documents/"].empty?
if catch('empty'){Dir.glob("#{RAILS_ROOT}/documents/"){throw 'empty'}}
if Dir.entries("#{RAILS_ROOT}/documents/") == []
, but none seem to work for me.
--
Posted via
http://www.ruby-...
.
3 Answers
pphetra
11/9/2007 9:34:00 AM
0
On Nov 9, 1:54 pm, Peter Marks <petertma...@gmail.com> wrote:
> if Dir["#{RAILS_ROOT}/documents/"].empty?
try this.
if Dir["#{RAILS_ROOT}/documents/*"].empty?
Peter Marks
11/9/2007 10:58:00 AM
0
pphetra wrote:
> try this.
>
> if Dir["#{RAILS_ROOT}/documents/*"].empty?
Ahh, didn't see the stars. Thanks pphetra :)
--
Posted via
http://www.ruby-...
.
Robert Klemme
11/9/2007 5:45:00 PM
0
2007/11/9, Peter Marks <petertmarks@gmail.com>:
> I see this question was asked a while back
> (
http://www.ruby-forum.com/t...
), but I'm having trouble
> implementing any of the solutions. I have tried:
>
> if Dir["#{RAILS_ROOT}/documents/"].empty?
You need the star here as well - as you probably know by now.
> if catch('empty'){Dir.glob("#{RAILS_ROOT}/documents/"){throw 'empty'}}
I guess that should rather read
unless catch('non_empty'){Dir.glob("#{RAILS_ROOT}/documents/*"){throw
'non_empty'}}
Or am I missing something?
> if Dir.entries("#{RAILS_ROOT}/documents/") == []
(see above)
> , but none seem to work for me.
Cheers
robert
--
use.inject do |as, often| as.you_can - without end
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Best way to test if a directory is empty
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password