Create a directory

From CodeCodex

Revision as of 15:02, 17 February 2012 by 213.115.10.98 (Talk)

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

Implementations

Common Lisp

(ensure-directories-exist "/path/name/")

See the CLHS: ensure-directories-exist

Erlang

file:make_dir("foo").

C#

DirectoryInfo di = new DirectoryInfo("directoryName");
if(di.Exist == false)
    di.Create();

// or direct
Directory.CreateDirectory("directoryName");


Java

    // Create a directory; all ancestor directories must exist
    boolean success = (new File("directoryName")).mkdir();
    if (!success) {
        // Directory creation failed
    }
    
    // Create a directory; all non-existent ancestor directories are
    // automatically created
    success = (new File("directoryName")).mkdirs();
    if (!success) {
        // Directory creation failed
    }

OCaml

# Unix.mkdir "foo" 0o666;;
- : unit = ()

Perl

mkdir $dir;

use File::Path qw(mkpath);
mkpath $dir;

PHP

  mkdir('foo');

Python

import os
os.mkdir("foo", 0666)

Ruby

Dir.mkdir('foo')

Tcl

file mkdir foo