Erlang Central

Difference between revisions of "File exist"

From ErlangCentral Wiki

Line 1: Line 1:
There are many ways to test if a file exists in Erlang. Here are some examples:
+
The function ''filelib:is_regular/1'' could be used to verify that an file do exist or dose not exist.
 +
 
 +
Here is a example:
 
<code>
 
<code>
case filelib:is_regular(Name) of
+
case filelib:is_regular(FileName) of
true ->
+
    true ->
    io:format("File exist.\n");
+
        io:format("File exist.\n");
false ->
+
    false ->
    io:format("File dose not exist.\n")
+
        io:format("File dose not exist.\n")
 
end
 
end
 
</code>
 
</code>
 
[[Category:CookBook]] [[Category:FileRecipes]]
 
[[Category:CookBook]] [[Category:FileRecipes]]

Revision as of 07:11, 15 October 2007

The function filelib:is_regular/1 could be used to verify that an file do exist or dose not exist.

Here is a example:

case filelib:is_regular(FileName) of
    true ->
        io:format("File exist.\n");
    false ->
        io:format("File dose not exist.\n")
end