lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Fri, Oct 24, 2008 at 6:20 AM, TheLonelyStar <> 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