Erlang Central

Maybe Make Directory

Revision as of 02:36, 4 September 2006 by Bfulgham (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Problem

You want to create a directory only if it doesn't already exist.

Solution

The filelib:ensure_dir function does this for you:

1> filelib:ensure_dir("/what/a/great/test").
ok

Discussion

In many scripting applications you have to create a directory the first time the script is run (for example, to store log files) but not on future runs of the script. Luckily, the Erlang standard libraries provides this useful function that solves this problem nicely.