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

/ Erlang.FileMakePlatformIndependentPath

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

Creating a Platform Independent Path

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.

Contributors

Based on work by NoelWelsh and BrentFulgham.

-- BrentAFulgham - 01 Sep 2004

Comments

CookbookForm
TopicType: Recipe
ParentTopic: FileRecipes
TopicOrder: 020

 
 
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