Difference between revisions of "Create a directory"

From CodeCodex

(OCaml)
(Ruby)
Line 27: Line 27:
 
- : unit = ()
 
- : unit = ()
 
</pre>
 
</pre>
 
===PHP===
 
<highlightsyntax>
 
  mkdir('foo');
 
</highlightsyntax>
 
  
 
===Perl===
 
===Perl===
Line 40: Line 35:
 
mkpath $dir;
 
mkpath $dir;
 
</HIGHLIGHTSYNTAX>
 
</HIGHLIGHTSYNTAX>
 +
 +
===PHP===
 +
<highlightsyntax language="php3">
 +
  mkdir('foo');
 +
</highlightsyntax>
  
 
===Python===
 
===Python===
Line 46: Line 46:
 
os.mkdir("foo", 0666)
 
os.mkdir("foo", 0666)
 
</HIGHLIGHTSYNTAX>
 
</HIGHLIGHTSYNTAX>
 +
 +
===Ruby===
 +
<pre>
 +
Dir.mkdir('foo')
 +
</pre>
 +
 
[[Category:Common Lisp]]
 
[[Category:Common Lisp]]
 
[[Category:Java]]
 
[[Category:Java]]
 +
[[Category:Objective Caml]]
 
[[Category:Perl]]
 
[[Category:Perl]]
[[Category:Python]]
 
 
[[Category:PHP]]
 
[[Category:PHP]]
 +
[[Category:Python]]
 +
[[Category:Ruby]]
 
[[Category:I/O]]
 
[[Category:I/O]]
[[Category:Objective Caml]]
 

Revision as of 01:28, 17 July 2010

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