Erlang Central

Create Deep Directory

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

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

Problem

You want to be able to create a directory without having to verify each parent element of the directory exists.

Solution

The ensure_dir function of the filelib module checks that all parent directories for a given directory name exists, creating any elements if needed.

1> filelib:ensure_dir("/this/path/will/soon/exist").
ok

Discussion

This is one area where Erlang makes it very easy. This useful library module helps us avoid a lot of repetitive boilerplate code.