Make directory path: Difference between revisions

Content added Content deleted
m (→‎{{header|Phix}}: added syntax colouring, marked p2js incompatible)
m (syntax highlighting fixup automation)
Line 14: Line 14:


=={{header|11l}}==
=={{header|11l}}==
<lang 11l>fs:create_dirs(path)</lang>
<syntaxhighlight lang="11l">fs:create_dirs(path)</syntaxhighlight>


=={{header|Ada}}==
=={{header|Ada}}==
<lang Ada>with Ada.Command_Line;
<syntaxhighlight lang="ada">with Ada.Command_Line;
with Ada.Directories;
with Ada.Directories;
with Ada.Text_IO;
with Ada.Text_IO;
Line 33: Line 33:
Ada.Directories.Create_Path (Path);
Ada.Directories.Create_Path (Path);
end;
end;
end Make_Directory_Path;</lang>
end Make_Directory_Path;</syntaxhighlight>


=={{header|Aime}}==
=={{header|Aime}}==
<lang aime>void
<syntaxhighlight lang="aime">void
mkdirp(text path)
mkdirp(text path)
{
{
Line 56: Line 56:


0;
0;
}</lang>
}</syntaxhighlight>


=={{header|AppleScript}}==
=={{header|AppleScript}}==
Line 64: Line 64:
`createDirectoryAtPath:withIntermediateDirectories:attributes:error:`
`createDirectoryAtPath:withIntermediateDirectories:attributes:error:`


<lang AppleScript>use framework "Foundation"
<syntaxhighlight lang="applescript">use framework "Foundation"
use scripting additions
use scripting additions


Line 121: Line 121:
on nothing(msg)
on nothing(msg)
{nothing:true, msg:msg}
{nothing:true, msg:msg}
end nothing</lang>
end nothing</syntaxhighlight>


=={{header|Arturo}}==
=={{header|Arturo}}==


<lang rebol>write.directory "path/to/some/directory" ø</lang>
<syntaxhighlight lang="rebol">write.directory "path/to/some/directory" ø</syntaxhighlight>


=={{header|AWK}}==
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f MAKE_DIRECTORY_PATH.AWK path ...
# syntax: GAWK -f MAKE_DIRECTORY_PATH.AWK path ...
BEGIN {
BEGIN {
Line 143: Line 143:
return system(cmd)
return system(cmd)
}
}
</syntaxhighlight>
</lang>
<p>sample command and output under Windows 8:</p>
<p>sample command and output under Windows 8:</p>
<pre>
<pre>
Line 154: Line 154:


=={{header|C}}==
=={{header|C}}==
<lang c>#include <stdio.h>
<syntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <libgen.h>
#include <libgen.h>
Line 185: Line 185:
}
}
return 0;
return 0;
}</lang>
}</syntaxhighlight>


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
<lang csharp>System.IO.Directory.CreateDirectory(path)</lang>
<syntaxhighlight lang="csharp">System.IO.Directory.CreateDirectory(path)</syntaxhighlight>


=={{header|C++|CPP}}==
=={{header|C++|CPP}}==
<lang cpp>
<syntaxhighlight lang="cpp">
#include <filesystem>
#include <filesystem>
#include <iostream>
#include <iostream>
Line 218: Line 218:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|Clojure}}==
=={{header|Clojure}}==
<lang clojure>(defn mkdirp [path]
<syntaxhighlight lang="clojure">(defn mkdirp [path]
(let [dir (java.io.File. path)]
(let [dir (java.io.File. path)]
(if (.exists dir)
(if (.exists dir)
true
true
(.mkdirs dir))))</lang>
(.mkdirs dir))))</syntaxhighlight>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==
<lang lisp>
<syntaxhighlight lang="lisp">
(ensure-directories-exist "your/path/name")
(ensure-directories-exist "your/path/name")
</syntaxhighlight>
</lang>


=={{header|D}}==
=={{header|D}}==
<lang D>import std.stdio;
<syntaxhighlight lang="d">import std.stdio;


void main() {
void main() {
Line 261: Line 261:
}
}
}
}
}</lang>
}</syntaxhighlight>
=={{header|Delphi}}==
=={{header|Delphi}}==
{{libheader| System.SysUtils}}
{{libheader| System.SysUtils}}
{{libheader| System.IOUtils}}
{{libheader| System.IOUtils}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program Make_directory_path;
program Make_directory_path;


Line 289: Line 289:
Writeln('Created "', path2, '" sucessfull.');
Writeln('Created "', path2, '" sucessfull.');
Readln;
Readln;
end.</lang>
end.</syntaxhighlight>


=={{header|Elixir}}==
=={{header|Elixir}}==
Tries to create the directory `path`. Missing parent directories are created.
Tries to create the directory `path`. Missing parent directories are created.
<lang elixir>File.mkdir_p("./path/to/dir")</lang>
<syntaxhighlight lang="elixir">File.mkdir_p("./path/to/dir")</syntaxhighlight>


=={{header|ERRE}}==
=={{header|ERRE}}==
ERRE has the procedure "OS_MKDIR" in PC.LIB standard library, that creates a directory with
ERRE has the procedure "OS_MKDIR" in PC.LIB standard library, that creates a directory with
all missing parents. Existing directory are simply ignored.
all missing parents. Existing directory are simply ignored.
<lang ERRE>OS_MKDIR("C:\EXAMPLES\03192015")</lang>
<syntaxhighlight lang="erre">OS_MKDIR("C:\EXAMPLES\03192015")</syntaxhighlight>


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
Line 326: Line 326:
=={{header|Factor}}==
=={{header|Factor}}==
The <code>make-directories</code> word performs this task. Note the value of <code>current-directory</code> is used as the base directory if a relative pathname is given.
The <code>make-directories</code> word performs this task. Note the value of <code>current-directory</code> is used as the base directory if a relative pathname is given.
<lang factor>USE: io.directories
<syntaxhighlight lang="factor">USE: io.directories
"path/to/dir" make-directories</lang>
"path/to/dir" make-directories</syntaxhighlight>
The implementation of <code>make-directories</code>:
The implementation of <code>make-directories</code>:
<lang factor>USING: combinators.short-circuit io.backend io.files
<syntaxhighlight lang="factor">USING: combinators.short-circuit io.backend io.files
io.pathnames kernel sequences ;
io.pathnames kernel sequences ;
IN: io.directories
IN: io.directories
Line 335: Line 335:
normalize-path trim-tail-separators dup
normalize-path trim-tail-separators dup
{ [ "." = ] [ root-directory? ] [ empty? ] [ exists? ] } 1||
{ [ "." = ] [ root-directory? ] [ empty? ] [ exists? ] } 1||
[ make-parent-directories dup make-directory ] unless drop ;</lang>
[ make-parent-directories dup make-directory ] unless drop ;</syntaxhighlight>






=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>#ifdef __FB_WIN32__
<syntaxhighlight lang="freebasic">#ifdef __FB_WIN32__
Dim pathname As String = "Ring\docs"
Dim pathname As String = "Ring\docs"
#else
#else
Line 356: Line 356:
Print "error: unable to create folder " & pathname & " in the current path."
Print "error: unable to create folder " & pathname & " in the current path."
End If
End If
Sleep</lang>
Sleep</syntaxhighlight>




=={{header|Gambas}}==
=={{header|Gambas}}==
<lang gambas>Public Sub Form_Open()
<syntaxhighlight lang="gambas">Public Sub Form_Open()


If Not Exist(User.home &/ "TestFolder") Then Mkdir User.Home &/ "TestFolder"
If Not Exist(User.home &/ "TestFolder") Then Mkdir User.Home &/ "TestFolder"


End</lang>
End</syntaxhighlight>


=={{header|Go}}==
=={{header|Go}}==
The standard packages include <tt>[http://golang.org/pkg/os/#MkdirAll os.MkdirAll]</tt> which does exactly this
The standard packages include <tt>[http://golang.org/pkg/os/#MkdirAll os.MkdirAll]</tt> which does exactly this
(and its source is also available via that link).
(and its source is also available via that link).
<lang go> os.MkdirAll("/tmp/some/path/to/dir", 0770)</lang>
<syntaxhighlight lang="go"> os.MkdirAll("/tmp/some/path/to/dir", 0770)</syntaxhighlight>


=={{header|Haskell}}==
=={{header|Haskell}}==
<syntaxhighlight lang="haskell">
<lang Haskell>
import System.Directory (createDirectory, setCurrentDirectory)
import System.Directory (createDirectory, setCurrentDirectory)
import Data.List.Split (splitOn)
import Data.List.Split (splitOn)
Line 380: Line 380:
let path = splitOn "/" "path/to/dir"
let path = splitOn "/" "path/to/dir"
mapM_ (\x -> createDirectory x >> setCurrentDirectory x) path
mapM_ (\x -> createDirectory x >> setCurrentDirectory x) path
</syntaxhighlight>
</lang>


=={{header|J}}==
=={{header|J}}==
Line 386: Line 386:
The verb <code>pathcreate</code> in the addon package [http://www.jsoftware.com/jwiki/Addons/general/dirutils general/dirutils] will create any non-existing directories in a path. It works on Windows, Linux and OS X.
The verb <code>pathcreate</code> in the addon package [http://www.jsoftware.com/jwiki/Addons/general/dirutils general/dirutils] will create any non-existing directories in a path. It works on Windows, Linux and OS X.
<lang J>require 'general/dirutils'
<syntaxhighlight lang="j">require 'general/dirutils'
pathcreate '/tmp/some/path/to/dir'</lang>
pathcreate '/tmp/some/path/to/dir'</syntaxhighlight>


Code is similar to the following:
Code is similar to the following:
<lang J>pathcreate=: monad define
<syntaxhighlight lang="j">pathcreate=: monad define
todir=. termsep_j_ jpathsep y
todir=. termsep_j_ jpathsep y
todirs=. }. ,each /\ <;.2 todir NB. base dirs
todirs=. }. ,each /\ <;.2 todir NB. base dirs
Line 406: Line 406:
)
)


direxist=: 2 = ftype&>@:boxopen</lang>
direxist=: 2 = ftype&>@:boxopen</syntaxhighlight>


=={{header|Java}}==
=={{header|Java}}==
The Java method for this is ''mkdirs'' and can be found in java.io.File. The source is in the ''src.zip'' of the JDK root directory.
The Java method for this is ''mkdirs'' and can be found in java.io.File. The source is in the ''src.zip'' of the JDK root directory.
<lang java>import java.io.File;
<syntaxhighlight lang="java">import java.io.File;


public interface Test {
public interface Test {
Line 423: Line 423:
}
}
}
}
}</lang>
}</syntaxhighlight>


=={{header|JavaScript}}==
=={{header|JavaScript}}==
Line 430: Line 430:
Simplified version of the popular [https://www.npmjs.org/package/mkdirp mkdirp library]:
Simplified version of the popular [https://www.npmjs.org/package/mkdirp mkdirp library]:


<lang Javascript>var path = require('path');
<syntaxhighlight lang="javascript">var path = require('path');
var fs = require('fs');
var fs = require('fs');


Line 456: Line 456:
}
}
});
});
}</lang>
}</syntaxhighlight>


=={{header|Julia}}==
=={{header|Julia}}==
{{works with|Julia|0.6}}
{{works with|Julia|0.6}}


<lang julia>mkpath("/tmp/unusefuldir/helloworld.d/test123")</lang>
<syntaxhighlight lang="julia">mkpath("/tmp/unusefuldir/helloworld.d/test123")</syntaxhighlight>


=={{header|Kotlin}}==
=={{header|Kotlin}}==
<lang scala>// version 1.0.6
<syntaxhighlight lang="scala">// version 1.0.6


import java.io.File
import java.io.File
Line 473: Line 473:
if (success) println("Directory path was created successfully")
if (success) println("Directory path was created successfully")
else println("Failed to create directory path")
else println("Failed to create directory path")
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 483: Line 483:
The ubiquitous luafilesystem module contains lfs.mkdir but this does not have an option equivalent to the posix mkdir -p.
The ubiquitous luafilesystem module contains lfs.mkdir but this does not have an option equivalent to the posix mkdir -p.
Instead, the function shown here uses package.config to determine the correct directory separator for the OS and then iterates over the path string to create each individual folder in turn.
Instead, the function shown here uses package.config to determine the correct directory separator for the OS and then iterates over the path string to create each individual folder in turn.
<lang Lua>require("lfs")
<syntaxhighlight lang="lua">require("lfs")


function mkdir (path)
function mkdir (path)
Line 493: Line 493:
end
end


mkdir("C:\\path\\to\\dir") -- Quoting backslashes requires escape sequence</lang>
mkdir("C:\\path\\to\\dir") -- Quoting backslashes requires escape sequence</syntaxhighlight>
Note that attempting to run lfs.mkdir for a path that already exists writes no changes to disk and returns nil.
Note that attempting to run lfs.mkdir for a path that already exists writes no changes to disk and returns nil.


=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
Creates directory specified by path, creating intermediate directories as necessary, and never fails if path already exists.
Creates directory specified by path, creating intermediate directories as necessary, and never fails if path already exists.
<lang Mathematica>mkdirp[path_] := Quiet[CreateDirectory[path,{CreateIntermediateDirectories->True}],{CreateDirectory::filex}]</lang>
<syntaxhighlight lang="mathematica">mkdirp[path_] := Quiet[CreateDirectory[path,{CreateIntermediateDirectories->True}],{CreateDirectory::filex}]</syntaxhighlight>


=={{header|NewLISP}}==
=={{header|NewLISP}}==
<lang newlisp>(define (mkdir-p mypath)
<syntaxhighlight lang="newlisp">(define (mkdir-p mypath)
(if (= "/" (mypath 0)) ;; Abs or relative path?
(if (= "/" (mypath 0)) ;; Abs or relative path?
(setf /? "/")
(setf /? "/")
Line 518: Line 518:
;; ... or calling OS command directly.
;; ... or calling OS command directly.
(! "mkdir -p /tmp/rosetta/test2")
(! "mkdir -p /tmp/rosetta/test2")
(exit)</lang>
(exit)</syntaxhighlight>


=={{header|Nim}}==
=={{header|Nim}}==
Note that the procedure "createDir" used here doesn’t raise an exception if the directory already exists because for current situations this is not an error. An exception is raised if the directory doesn’t exist after the call, if, for instance, permission is not allowed to create the directory.
Note that the procedure "createDir" used here doesn’t raise an exception if the directory already exists because for current situations this is not an error. An exception is raised if the directory doesn’t exist after the call, if, for instance, permission is not allowed to create the directory.
<lang Nim>import os
<syntaxhighlight lang="nim">import os


try:
try:
Line 528: Line 528:
echo "Directory now exists."
echo "Directory now exists."
except OSError:
except OSError:
echo "Failed to create the directory."</lang>
echo "Failed to create the directory."</syntaxhighlight>


=={{header|Objeck}}==
=={{header|Objeck}}==
<lang objeck>class Program {
<syntaxhighlight lang="objeck">class Program {
function : Main(args : String[]) ~ Nil {
function : Main(args : String[]) ~ Nil {
System.IO.File.Directory->CreatePath("your/path/name")->PrintLine();
System.IO.File.Directory->CreatePath("your/path/name")->PrintLine();
}
}
}</lang>
}</syntaxhighlight>




=={{header|OCaml}}==
=={{header|OCaml}}==


<lang ocaml>#load "unix.cma"
<syntaxhighlight lang="ocaml">#load "unix.cma"


let mkdir_p ~path ~perms =
let mkdir_p ~path ~perms =
Line 553: Line 553:


let () =
let () =
mkdir_p "path/to/dir" 0o700</lang>
mkdir_p "path/to/dir" 0o700</syntaxhighlight>


=={{header|Perl}}==
=={{header|Perl}}==
Line 559: Line 559:
Using the File::Path core module:
Using the File::Path core module:


<lang perl>use File::Path qw(make_path);
<syntaxhighlight lang="perl">use File::Path qw(make_path);


make_path('path/to/dir')</lang>
make_path('path/to/dir')</syntaxhighlight>


=={{header|Phix}}==
=={{header|Phix}}==
There's a builtin for that
There's a builtin for that
<!--<lang Phix>(notonline)-->
<!--<syntaxhighlight lang="phix">(notonline)-->
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (file i/o)</span>
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (file i/o)</span>
<span style="color: #008080;">if</span> <span style="color: #008080;">not</span> <span style="color: #000000;">create_directory</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"myapp/interface/letters"</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
<span style="color: #008080;">if</span> <span style="color: #008080;">not</span> <span style="color: #000000;">create_directory</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"myapp/interface/letters"</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">crash</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"Filesystem problem - could not create the new folder"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">crash</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"Filesystem problem - could not create the new folder"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
The implementation in builtins/pfile.e is as follows (see there for initf() etc):
The implementation in builtins/pfile.e is as follows (see there for initf() etc):
<!--<lang Phix>-->
<!--<syntaxhighlight lang="phix">-->
<span style="color: #008080;">global</span> <span style="color: #008080;">function</span> <span style="color: #000000;">create_directory</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">name</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">mode</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0o700</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">bool</span> <span style="color: #000000;">make_parent</span><span style="color: #0000FF;">=</span><span style="color: #004600;">true</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">global</span> <span style="color: #008080;">function</span> <span style="color: #000000;">create_directory</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">name</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">mode</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0o700</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">bool</span> <span style="color: #000000;">make_parent</span><span style="color: #0000FF;">=</span><span style="color: #004600;">true</span><span style="color: #0000FF;">)</span>
Line 612: Line 612:
<span style="color: #008080;">return</span> <span style="color: #000000;">ret</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">ret</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
Of course you could also use system("mkdir -p path/to/dir") or whatever.
Of course you could also use system("mkdir -p path/to/dir") or whatever.


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
<lang PicoLisp>(call "mkdir" "-p" "path/to/dir")</lang>
<syntaxhighlight lang="picolisp">(call "mkdir" "-p" "path/to/dir")</syntaxhighlight>


=={{header|PowerShell}}==
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
<lang PowerShell>
New-Item -Path ".\path\to\dir" -ItemType Directory -ErrorAction SilentlyContinue
New-Item -Path ".\path\to\dir" -ItemType Directory -ErrorAction SilentlyContinue
</syntaxhighlight>
</lang>


=={{header|Python}}==
=={{header|Python}}==
<syntaxhighlight lang="python">
<lang Python>
from errno import EEXIST
from errno import EEXIST
from os import mkdir, curdir
from os import mkdir, curdir
Line 648: Line 648:
if e.errno != EEXIST:
if e.errno != EEXIST:
raise
raise
</syntaxhighlight>
</lang>


Above is a modified version of the standard library's <code>os.makedirs</code>, for pedagogical purposes. In practice, you would be more likely to use the standard library call:
Above is a modified version of the standard library's <code>os.makedirs</code>, for pedagogical purposes. In practice, you would be more likely to use the standard library call:


<syntaxhighlight lang="python">
<lang Python>
def mkdirp(path):
def mkdirp(path):
try:
try:
Line 660: Line 660:
pass
pass
else: raise
else: raise
</syntaxhighlight>
</lang>


In Python3 this becomes even simpler:
In Python3 this becomes even simpler:


<syntaxhighlight lang="python">
<lang Python>
def mkdirp(path):
def mkdirp(path):
os.makedirs(path, exist_ok=True)
os.makedirs(path, exist_ok=True)
</syntaxhighlight>
</lang>


=={{header|Racket}}==
=={{header|Racket}}==
Line 679: Line 679:
</blockquote>
</blockquote>


<lang racket>#lang racket
<syntaxhighlight lang="racket">#lang racket
(define path-str "/tmp/woo/yay")
(define path-str "/tmp/woo/yay")
(define path/..-str "/tmp/woo")
(define path/..-str "/tmp/woo")
Line 700: Line 700:
(make-directory* path-str)
(make-directory* path-str)


(report-path-exists)</lang>
(report-path-exists)</syntaxhighlight>


{{out}}
{{out}}
Line 717: Line 717:
There is a built-in function for this:
There is a built-in function for this:


<lang perl6>mkdir 'path/to/dir'</lang>
<syntaxhighlight lang="raku" line>mkdir 'path/to/dir'</syntaxhighlight>


Alternatively, a custom solution (as per task description) that only uses the built-in <tt>mkdir</tt> non-recursively. The "triangle reduce" meta-operator <code>[\ ]</code> is used get the intermediate results of a left fold with the comma operator on the list of path elements.
Alternatively, a custom solution (as per task description) that only uses the built-in <tt>mkdir</tt> non-recursively. The "triangle reduce" meta-operator <code>[\ ]</code> is used get the intermediate results of a left fold with the comma operator on the list of path elements.


<lang perl6>for [\,] $*SPEC.splitdir("../path/to/dir") -> @path {
<syntaxhighlight lang="raku" line>for [\,] $*SPEC.splitdir("../path/to/dir") -> @path {
mkdir $_ unless .e given $*SPEC.catdir(@path).IO;
mkdir $_ unless .e given $*SPEC.catdir(@path).IO;
}</lang>
}</syntaxhighlight>


=={{header|REXX}}==
=={{header|REXX}}==
Line 731: Line 731:


Usage note: &nbsp; without the error messages being suppressed, the &nbsp; '''MKDIR''' &nbsp; command will issue an error message if the subdirectory (or its path) already exists.
Usage note: &nbsp; without the error messages being suppressed, the &nbsp; '''MKDIR''' &nbsp; command will issue an error message if the subdirectory (or its path) already exists.
<lang rexx>/*REXX program creates a directory (folder) and all its parent paths as necessary. */
<syntaxhighlight lang="rexx">/*REXX program creates a directory (folder) and all its parent paths as necessary. */
trace off /*suppress possible warning msgs.*/
trace off /*suppress possible warning msgs.*/


Line 737: Line 737:


'MKDIR' dPath "2>nul" /*alias could be used: MD dPath */
'MKDIR' dPath "2>nul" /*alias could be used: MD dPath */
/*stick a fork in it, we're done.*/</lang>
/*stick a fork in it, we're done.*/</syntaxhighlight>


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
System("mkdir C:\Ring\docs")
System("mkdir C:\Ring\docs")
isdir("C:\Ring\docs")
isdir("C:\Ring\docs")
Line 752: Line 752:
return false
return false
done
done
</syntaxhighlight>
</lang>


=={{header|Ruby}}==
=={{header|Ruby}}==
<lang ruby>require 'fileutils'
<syntaxhighlight lang="ruby">require 'fileutils'
FileUtils.mkdir_p("path/to/dir") </lang>
FileUtils.mkdir_p("path/to/dir") </syntaxhighlight>
mkdir_p also takes an array of pathnames instead of a single pathname as an argument.
mkdir_p also takes an array of pathnames instead of a single pathname as an argument.
mkdir_p is aliased as: mkpath, makedirs.
mkdir_p is aliased as: mkpath, makedirs.


=={{header|Run BASIC}}==
=={{header|Run BASIC}}==
<lang runbasic>
<syntaxhighlight lang="runbasic">
files #f, "c:\myDocs" ' check for directory
files #f, "c:\myDocs" ' check for directory
if #f hasanswer() then
if #f hasanswer() then
Line 771: Line 771:
else
else
shell$("mkdir c:\myDocs" ' if not exist make a directory
shell$("mkdir c:\myDocs" ' if not exist make a directory
end if</lang>
end if</syntaxhighlight>
The following info about files / directory
The following info about files / directory
FILE ACCESSOR methods
FILE ACCESSOR methods
Line 791: Line 791:


=={{header|Rust}}==
=={{header|Rust}}==
<lang rust>use std::fs;
<syntaxhighlight lang="rust">use std::fs;


fn main() {
fn main() {
fs::create_dir_all("./path/to/dir").expect("An Error Occured!")
fs::create_dir_all("./path/to/dir").expect("An Error Occured!")
}</lang>
}</syntaxhighlight>


=={{header|Scala}}==
=={{header|Scala}}==
<lang Scala>new java.io.File("/path/to/dir").mkdirs</lang>
<syntaxhighlight lang="scala">new java.io.File("/path/to/dir").mkdirs</syntaxhighlight>
Alternative (platform-independent) for the library function:
Alternative (platform-independent) for the library function:
<lang Scala>import java.io.File
<syntaxhighlight lang="scala">import java.io.File


def mkdirs(path: List[String]) = // return true if path was created
def mkdirs(path: List[String]) = // return true if path was created
Line 806: Line 806:


mkdirs(List("/path", "to", "dir"))
mkdirs(List("/path", "to", "dir"))
</syntaxhighlight>
</lang>


=={{header|Seed7}}==
=={{header|Seed7}}==
Line 812: Line 812:
defines the function doMkdirCmd, which is used below.
defines the function doMkdirCmd, which is used below.


<lang seed7>$ include "seed7_05.s7i";
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "cli_cmds.s7i";
include "cli_cmds.s7i";


Line 818: Line 818:
begin
begin
doMkdirCmd(argv(PROGRAM), TRUE);
doMkdirCmd(argv(PROGRAM), TRUE);
end func;</lang>
end func;</syntaxhighlight>


The library cli_cmds.s7i defines also
The library cli_cmds.s7i defines also
Line 827: Line 827:
The function doMkdir is used in the alternate solution below:
The function doMkdir is used in the alternate solution below:


<lang seed7>$ include "seed7_05.s7i";
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "cli_cmds.s7i";
include "cli_cmds.s7i";


Line 836: Line 836:
parameters := join(argv(PROGRAM), " ");
parameters := join(argv(PROGRAM), " ");
doMkdir(parameters);
doMkdir(parameters);
end func;</lang>
end func;</syntaxhighlight>


=={{header|Sidef}}==
=={{header|Sidef}}==
<lang ruby>Dir.new(Dir.cwd, "path", "to", "dir").make_path; # works cross-platform</lang>
<syntaxhighlight lang="ruby">Dir.new(Dir.cwd, "path", "to", "dir").make_path; # works cross-platform</syntaxhighlight>


=={{header|Tcl}}==
=={{header|Tcl}}==
Tcl's built in <code>file mkdir</code> works exactly this way:
Tcl's built in <code>file mkdir</code> works exactly this way:
<lang tcl>file mkdir ./path/to/dir</lang>
<syntaxhighlight lang="tcl">file mkdir ./path/to/dir</syntaxhighlight>
If a directory cannot be made (e.g., because it would involve making a directory with the same name as an existing file) the command will throw a trappable error, as normal for Tcl commands.
If a directory cannot be made (e.g., because it would involve making a directory with the same name as an existing file) the command will throw a trappable error, as normal for Tcl commands.


Line 849: Line 849:
{{works with|Bourne Again SHell}}
{{works with|Bourne Again SHell}}


<lang bash>function mkdirp() { mkdir -p "$1"; }</lang>
<syntaxhighlight lang="bash">function mkdirp() { mkdir -p "$1"; }</syntaxhighlight>


=={{header|Visual Basic .NET}}==
=={{header|Visual Basic .NET}}==
{{trans|C#}}
{{trans|C#}}
<lang vbnet>Module Module1
<syntaxhighlight lang="vbnet">Module Module1


Sub Main()
Sub Main()
Line 859: Line 859:
End Sub
End Sub


End Module</lang>
End Module</syntaxhighlight>


=={{header|Wren}}==
=={{header|Wren}}==
{{libheader|DOME}}
{{libheader|DOME}}
Curiously, this can only be done at present from a DOME program. A minimal script to do it would be:
Curiously, this can only be done at present from a DOME program. A minimal script to do it would be:
<lang ecmascript>import "io" for FileSystem
<syntaxhighlight lang="ecmascript">import "io" for FileSystem


class Main {
class Main {
Line 878: Line 878:
}
}


var Game = Main.new()</lang>
var Game = Main.new()</syntaxhighlight>
<br>
<br>
However, this functionality will be added to Wren-cli when version 0.4.0 is officially released. The code needed will be as follows:
However, this functionality will be added to Wren-cli when version 0.4.0 is officially released. The code needed will be as follows:
<lang ecmascript>import "io" for Directory
<syntaxhighlight lang="ecmascript">import "io" for Directory


Directory.create("path/to/dir")</lang>
Directory.create("path/to/dir")</syntaxhighlight>


=={{header|zkl}}==
=={{header|zkl}}==
This is for Unix as zkl doesn't have a built in mkdir method.
This is for Unix as zkl doesn't have a built in mkdir method.
<lang zkl>System.cmd("mkdir -p ../foo/bar")</lang>
<syntaxhighlight lang="zkl">System.cmd("mkdir -p ../foo/bar")</syntaxhighlight>
The system error code is returned (0 in this case).
The system error code is returned (0 in this case).
<lang zkl>fcn mkdir(path) { System.cmd("mkdir -p "+path) }</lang>
<syntaxhighlight lang="zkl">fcn mkdir(path) { System.cmd("mkdir -p "+path) }</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>