[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How do I test for the existens of a file
- From: "James Dennett" <james.dennett@...>
- Date: Fri, 24 Oct 2008 13:03:19 -0700
On Fri, Oct 24, 2008 at 6:20 AM, TheLonelyStar <nabble2@lonely-star.org> wrote:
>
> Hi,
>
> I want to test if a specific file exist, and do something if yes. Like
>
> if <file exist> then
> <do something>
> else
> <do something else>
> end
>
> How do I do that?
Others have been helpful and answered your actual question. I'll just
throw out the usual caution that this is _usually_ the wrong question
to ask. Normally you check for a file's existence because you want to
_do_ something with that file. You'll need to check again when you
try to use the file that it's worked, and that provides a more robust
test (e.g., free of races, and reflects permissions) than an "is it
there" test. So generally by the time you've written the robust code,
the "is it there?" check buys you nothing except more code paths.
-- James