e r l a n g : c o o k b o o k

/ Erlang.FileMaybeMakeDirectory

This Web


WebHome 
WebChanges 
TOC
NewRecipe 
WebTopicList 
WebStatistics 

All Webs


Chicken
Cookbook
Erlang
Know
Main
Plugins
Sandbox
Scm
TWiki  

Erlang Links


Erlang.org
Erlang Wiki
ErlMan
Erlang Wiki
The Jungerl
Erlang-fr.org
Joe Armstrong
Lambda the Ultimate

Erlang Web Ring


[Prev]: Joe Armstrong's Page
[Next]: Joe Armstrong's Page

Making A Directory If It Doesn't Already Exist

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.


Comments about this recipe

Contributors

Based on work by NoelWelsh.

-- BrentAFulgham - 01 Sep 2004

CookbookForm
TopicType: Recipe
ParentTopic: FileRecipes
TopicOrder: 030

 
 
Copyright © 2004 by the contributing authors. All material on the Erlang Cookbook web site is the property of the contributing authors.
This material can be redistributed and/or modified under the terms of the GNU Lesser General Public License (LGPL), version 2.1, as published by the Free Software Foundation.
Ideas, requests, problems regarding Schematics Cookbook? Send feedback.
/ You are Main.guest