Erlang Central

Platform Independent Path

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

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

Problem

You want to create a directory in a platform independent way. The directory is several levels deep and you wish to create intermediate directories as necessary.

Solution

Use the ensure_dir procedure in Erlang's filelib module.

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

Discussion

Although the above directory tree looks like a POSIX file system, if this test is run on a Windows machine you will get the expected directory tree starting at the root of the current drive (usually C:). On a UNIX platform, you will get the expected directory tree.

As always your user permissions will limit what files and directories you are able to create or modify.