File exist
From Erlang Community
(Difference between revisions)
| Revision as of 07:11, 15 October 2007 (edit) Andreas.hillqvist (Talk | contribs) ← Previous diff |
Current revision (20:09, 18 October 2009) (edit) (undo) Ayrnieu (Talk | contribs) (redo; add race-condition warning.) |
||
| Line 1: | Line 1: | ||
| - | The function | + | The function filelib:is_file/1 returns true if its argument refers to an existing file or directory. filelib:is_regular/1 more narrowly returns true on regular files. |
| - | Here is a example: | ||
| <code> | <code> | ||
| - | + | assert_config(Filename) -> | |
| - | true | + | true = filelib:is_regular(Filename). |
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| </code> | </code> | ||
| + | |||
| + | Generally you should assume that files exist, are readable, etc. -- and gracefully handle your failures. You'll have to do this second part ''anyway'', as e.g. a file can be deleted after assert_config/1 succeeds and before your read_config/1 tries to open it. | ||
| + | |||
| [[Category:CookBook]] [[Category:FileRecipes]] | [[Category:CookBook]] [[Category:FileRecipes]] | ||
Current revision
The function filelib:is_file/1 returns true if its argument refers to an existing file or directory. filelib:is_regular/1 more narrowly returns true on regular files.
assert_config(Filename) ->
true = filelib:is_regular(Filename).
|
Generally you should assume that files exist, are readable, etc. -- and gracefully handle your failures. You'll have to do this second part anyway, as e.g. a file can be deleted after assert_config/1 succeeds and before your read_config/1 tries to open it.

Digg It
Del.icio.us
Reddit
Facebook
Stumble Upon
Technorati

