Forum: Ruby Best way to test for file existence?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2006-04-11 17:57
All,

What is the best way to determine the existence of a file (more
specifically, a directory)?

Are there Perl - like file test operators available?

Wes
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2006-04-11 17:59
File.exist?

Sorry to waste time.

Wes Gamble wrote:
> All,
>
> What is the best way to determine the existence of a file (more
> specifically, a directory)?
>
> Are there Perl - like file test operators available?
>
> Wes
7863582496e914f1ffce56f98d468f72?d=identicon&s=25 Nathan Olberding (nko)
on 2006-04-11 18:08
Wes Gamble wrote:
> File.exist?
>
> Sorry to waste time.

I was so excited to finally see a question I could answer! That raised
my spirits. Definitely not a waste of my time!
Ff63c03fd68754adbadd2c6314646bef?d=identicon&s=25 Bill Guindon (agorilla)
on 2006-04-11 18:30
(Received via mailing list)
On 4/11/06, Wes Gamble <weyus@att.net> wrote:
> File.exist?
>
> Sorry to waste time.
>
> Wes Gamble wrote:
> > All,
> >
> > What is the best way to determine the existence of a file (more
> > specifically, a directory)?

And since you're looking for directories, there's also:
File.directory?
47b1910084592eb77a032bc7d8d1a84e?d=identicon&s=25 Joel VanderWerf (Guest)
on 2006-04-11 19:53
(Received via mailing list)
Wes Gamble wrote:
> All,
>
> What is the best way to determine the existence of a file (more
> specifically, a directory)?
>
> Are there Perl - like file test operators available?
>
> Wes
>

$ ri test | cat
------------------------------------------------------------ Kernel#test
     test(int_cmd, file1 [, file2] ) => obj
------------------------------------------------------------------------
      Uses the integer <em>aCmd</em> to perform various tests on
      <em>file1</em> (first table below) or on <em>file1</em> and
      <em>file2</em> (second table).

      File tests on a single file:

        Test   Returns   Meaning
         ?A  | Time    | Last access time for file1
         ?b  | boolean | True if file1 is a block device
         ?c  | boolean | True if file1 is a character device
...

and so on...
This topic is locked and can not be replied to.