Create a directory

From CodeCodex

Revision as of 17:02, 5 January 2011 by 211.2.129.92 (Talk)

Implementations

Common Lisp

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

See the CLHS: ensure-directories-exist

Erlang

file:make_dir("foo").

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')