Difference between revisions of "Create a directory"

From CodeCodex

(Ruby)
(Erlang)
Line 6: Line 6:
 
See the CLHS: [http://www.lisp.org/HyperSpec/Body/fun_ensure-di_tories-exist.html#ensure-directories-exist ensure-directories-exist]
 
See the CLHS: [http://www.lisp.org/HyperSpec/Body/fun_ensure-di_tories-exist.html#ensure-directories-exist ensure-directories-exist]
  
===Java===
+
===Erlang===
 
<pre>
 
<pre>
 +
file:make_dir("foo").
 +
</pre>
 +
 +
===Java===
 +
<pre class="java">
 
     // Create a directory; all ancestor directories must exist
 
     // Create a directory; all ancestor directories must exist
 
     boolean success = (new File("directoryName")).mkdir();
 
     boolean success = (new File("directoryName")).mkdir();
Line 22: Line 27:
 
</pre>
 
</pre>
 
* Original Source: [http://javaalmanac.com/egs/java.io/pkg.html?l=rel#Files The Java Developers Almanac 1.4]
 
* Original Source: [http://javaalmanac.com/egs/java.io/pkg.html?l=rel#Files The Java Developers Almanac 1.4]
 +
 
===OCaml===
 
===OCaml===
 
<pre>
 
<pre>
Line 29: Line 35:
  
 
===Perl===
 
===Perl===
<HIGHLIGHTSYNTAX language="perl">
+
<pre class="perl">
 
mkdir $dir;
 
mkdir $dir;
  
 
use File::Path qw(mkpath);
 
use File::Path qw(mkpath);
 
mkpath $dir;
 
mkpath $dir;
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
===PHP===
 
===PHP===
<highlightsyntax language="php3">
+
<pre class="php">
 
   mkdir('foo');
 
   mkdir('foo');
</highlightsyntax>
+
</pre>
  
 
===Python===
 
===Python===
<HIGHLIGHTSYNTAX language="python">
+
<pre class="python">
 
import os
 
import os
 
os.mkdir("foo", 0666)
 
os.mkdir("foo", 0666)
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
===Ruby===
 
===Ruby===
<pre>
+
<pre class="ruby">
 
Dir.mkdir('foo')
 
Dir.mkdir('foo')
 
</pre>
 
</pre>
  
 
[[Category:Common Lisp]]
 
[[Category:Common Lisp]]
 +
[[Category:Erlang]]
 
[[Category:Java]]
 
[[Category:Java]]
 
[[Category:Objective Caml]]
 
[[Category:Objective Caml]]

Revision as of 17:02, 5 January 2011

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