Best way to test for file existence?


#1

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


#2

File.exist?

Sorry to waste time.

Wes G. 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


#3

Wes G. 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!


#4

Wes G. 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…


#5

On 4/11/06, Wes G. removed_email_address@domain.invalid wrote:

File.exist?

Sorry to waste time.

Wes G. 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?