Difference between revisions of "Create a directory"

From CodeCodex

(Erlang)
(Implementations)
 
(One intermediate revision by one other user not shown)
Line 10: Line 10:
 
file:make_dir("foo").
 
file:make_dir("foo").
 
</pre>
 
</pre>
 +
 +
=== C# ===
 +
<pre class="c#">
 +
DirectoryInfo di = new DirectoryInfo("directoryName");
 +
if(di.Exist == false)
 +
    di.Create();
 +
 +
// or direct
 +
Directory.CreateDirectory("directoryName");
 +
</pre>
 +
  
 
===Java===
 
===Java===
Line 57: Line 68:
 
Dir.mkdir('foo')
 
Dir.mkdir('foo')
 
</pre>
 
</pre>
 +
 +
=== Tcl ===
 +
<pre class="tcl">
 +
file mkdir foo
 +
</pre>
 +
  
 
[[Category:Common Lisp]]
 
[[Category:Common Lisp]]
 +
[[Category:C#]]
 
[[Category:Erlang]]
 
[[Category:Erlang]]
 
[[Category:Java]]
 
[[Category:Java]]
Line 66: Line 84:
 
[[Category:Python]]
 
[[Category:Python]]
 
[[Category:Ruby]]
 
[[Category:Ruby]]
 +
[[Category:Tcl]]
 
[[Category:I/O]]
 
[[Category:I/O]]

Latest revision as of 15:02, 17 February 2012

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