Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Check if directory exists

Reply
Thread Tools

Check if directory exists

 
 
Florian Schaf
Guest
Posts: n/a
 
      12-18-2007
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 via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Phrogz
Guest
Posts: n/a
 
      12-18-2007
On Dec 18, 10:15 am, Florian Schaf <(E-Mail Removed)> 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?
 
Reply With Quote
 
 
 
 
Karl von Laudermann
Guest
Posts: n/a
 
      12-18-2007
On Dec 18, 12:15 pm, Florian Schaf <(E-Mail Removed)> 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.
 
Reply With Quote
 
Christophe Mckeon
Guest
Posts: n/a
 
      12-18-2007
here are two ways:

File.directory? path

test ?d, path
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
anti
Guest
Posts: n/a
 
      01-25-2008
On Dec 18 2007, 9:15 am, Florian Schaf <(E-Mail Removed)> 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
 
Reply With Quote
 
Dan
Guest
Posts: n/a
 
      01-25-2008
[Note: parts of this message were removed to make it a legal post.]

File.directory? 'some/dir'



On Jan 25, 2008 8:59 PM, anti <(E-Mail Removed)> wrote:

> On Dec 18 2007, 9:15 am, Florian Schaf <(E-Mail Removed)> 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
>
>


 
Reply With Quote
 
Vassilis Rizopoulos
Guest
Posts: n/a
 
      01-25-2008
anti wrote:
> On Dec 18 2007, 9:15 am, Florian Schaf <(E-Mail Removed)> 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
>
>
>

Yep. And the long version would be

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


V.-

--
http://www.braveworld.net/riva


 
Reply With Quote
 
Lee Jarvis
Guest
Posts: n/a
 
      01-25-2008
Gavin Kistner wrote:
> On Dec 18, 10:15 am, Florian Schaf <(E-Mail Removed)> 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 via http://www.ruby-forum.com/.

 
Reply With Quote
 
Robby Robby
Guest
Posts: n/a
 
      05-08-2009
Lee Jarvis wrote:
> Gavin Kistner wrote:
>> On Dec 18, 10:15 am, Florian Schaf <(E-Mail Removed)> 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 via http://www.ruby-forum.com/.

 
Reply With Quote
 
Nick Larson
Guest
Posts: n/a
 
      07-01-2009
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 via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check if a directory exists? folder.exists() does not work! Ulf Meinhardt Java 8 08-28-2009 12:26 PM
How to check if all *.jars in my CLASSPATH really exists? Automatic check (not manual) possible? Jason Stacy Java 2 04-27-2008 08:14 AM
Check if a directory exists in a network drive? Joris De Groote ASP .Net 2 04-11-2006 04:39 PM
Check to see if Virtual Directory exists Pgar ASP .Net 1 11-15-2004 09:03 PM
check if a directory exists calca77 C++ 3 01-09-2004 10:51 AM



Advertisments