Ruby Forum Ruby > Check if directory exists

Posted by Florian Schaf (schaf88)
on 18.12.2007 18:15
hi!
Can anyone tell me how I can check whether a directory exists or not? I
didnt find anything via google or in the docs
thanks!
Posted by Gavin Kistner (phrogz)
on 18.12.2007 18:31
(Received via mailing list)
On Dec 18, 10:15 am, Florian Schaf <flo.sc...@gmail.com> wrote:
> hi!
> Can anyone tell me how I can check whether a directory exists or not? I
> didnt find anything via google or in the docs
> thanks!

What did you Google for, and where did you search in the docs?
Posted by Christophe Mckeon (polypus)
on 18.12.2007 19:01
here are two ways:

File.directory? path

test ?d, path
Posted by Karl von Laudermann (Guest)
on 18.12.2007 19:04
(Received via mailing list)
On Dec 18, 12:15 pm, Florian Schaf <flo.sc...@gmail.com> wrote:
> hi!
> Can anyone tell me how I can check whether a directory exists or not? I
> didnt find anything via google or in the docs

File#exists? works for directories as well as files. You could then
use File#directory? to verify that the item is a directory, if it
exists.
Posted by anti (Guest)
on 25.01.2008 11:30
(Received via mailing list)
On Dec 18 2007, 9:15 am, Florian Schaf <flo.sc...@gmail.com> wrote:
> hi!
> Can anyone tell me how I can check whether a directory exists or not? I
> didnt find anything via google or in the docs
> thanks!
> --
> Posted viahttp://www.ruby-forum.com/.

if Dir["C:/ruby"] != nil
  puts 'Yeehoooo !'
else
  puts 'no such directory'
end
Posted by Dan (Guest)
on 25.01.2008 12:29
(Received via mailing list)
File.directory? 'some/dir'
Posted by Vassilis Rizopoulos (Guest)
on 25.01.2008 12:37
(Received via mailing list)
anti wrote:
> if Dir["C:/ruby"] != nil
>   puts 'Yeehoooo !'
> else
>   puts 'no such directory'
> end
>
>
>   
Yep. And the long version would be

path="/some/path"
if File.exists?(path) && File.directory?(path)
    puts "yeeha"
else
    puts "bummer"
end

;)
V.-
Posted by Lee Jarvis (hiroshi)
on 25.01.2008 14:19
Gavin Kistner wrote:
> On Dec 18, 10:15 am, Florian Schaf <flo.sc...@gmail.com> wrote:
>> hi!
>> Can anyone tell me how I can check whether a directory exists or not? I
>> didnt find anything via google or in the docs
>> thanks!
> 
> What did you Google for, and where did you search in the docs?

Its a shame people had to post solutions afterwards. That would of been 
interesting.
Posted by Robby Robby (robby247365)
on 08.05.2009 21:33
Lee Jarvis wrote:
> Gavin Kistner wrote:
>> On Dec 18, 10:15 am, Florian Schaf <flo.sc...@gmail.com> wrote:
>>> hi!
>>> Can anyone tell me how I can check whether a directory exists or not? I
>>> didnt find anything via google or in the docs
>>> thanks!
>> 
>> What did you Google for, and where did you search in the docs?
> 
> Its a shame people had to post solutions afterwards. That would of been 
> interesting.

Well im glad they posted solutions, for I googled "ruby directory 
exists" and got the answer from here.
Posted by Grails Rules (ihateror)
on 01.07.2009 16:31
Lee Jarvis wrote:
> 
> Its a shame people had to post solutions afterwards. That would of been 
> interesting.
>

This is why the Ruby and RoR community sucks.
Posted by Tom Cloyd (Guest)
on 02.07.2009 03:21
(Received via mailing list)
Nick Larson wrote:
> Lee Jarvis wrote:
>   
>> Its a shame people had to post solutions afterwards. That would of been 
>> interesting.
>>
>>     
>
> This is why the Ruby and RoR community sucks.
>
>   
What really sucks is list posts like this which fall out of the sky
without any internal context.

What this post is about is anyone's guess.

What a time-waster!

t.

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Posted by 邓鹏 (Guest)
on 02.07.2009 08:19
(Received via mailing list)
2009/7/2 Tom Cloyd <tomcloyd@comcast.net>

>>
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
>
How to do ?


--
Thanks !


Kevin Peng