Create a directory

From CodeCodex

Implementations[edit]

Common Lisp[edit]

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

See the CLHS: ensure-directories-exist

Erlang[edit]

file:make_dir("foo").

C#[edit]

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

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


Java[edit]

    // 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[edit]

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

Perl[edit]

mkdir $dir;

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

PHP[edit]

  mkdir('foo');

Python[edit]

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

Ruby[edit]

Dir.mkdir('foo')

Tcl[edit]

file mkdir foo