Create a directory

From CodeCodex

Revision as of 01:28, 17 July 2010 by 211.2.129.92 (Talk)

Implementations

Common Lisp

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

See the CLHS: ensure-directories-exist

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

<HIGHLIGHTSYNTAX language="perl"> mkdir $dir;

use File::Path qw(mkpath); mkpath $dir; </HIGHLIGHTSYNTAX>

PHP

<highlightsyntax language="php3">

 mkdir('foo');

</highlightsyntax>

Python

<HIGHLIGHTSYNTAX language="python"> import os os.mkdir("foo", 0666) </HIGHLIGHTSYNTAX>

Ruby

Dir.mkdir('foo')