Make directory path: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H (future CLI version)
No edit summary
m (→‎{{header|Wren}}: Changed to Wren S/H (future CLI version))
 
(3 intermediate revisions by 2 users not shown)
Line 580:
=={{header|OCaml}}==
 
<syntaxhighlight lang="ocaml">#loadlet "unix.cma"rec mkdir_p path perm =
if path <> "" then
 
try Unix.mkdir thispath perm perms;with
let mkdir_p ~path ~perms =
| Unix.Unix_error (EEXIST, _, _) when Sys.is_directory path -> ()
let ps = String.split_on_char '/' path in
| Unix.Unix_error (ENOENT, _, _) ->
let rec aux acc = function [] -> ()
mkdir_p (Filename.dirname path) perm;
| p::ps ->
Unix.mkdir path perm</syntaxhighlight>Requires the standard <code>[https://ocaml.org/manual/libunix.html unix]</code> library
let this = String.concat Filename.dir_sep (List.rev (p::acc)) in
Unix.mkdir this perms;
aux (p::acc) ps
in
aux [] ps
 
let () =
mkdir_p "path/to/dir" 0o700</syntaxhighlight>
 
=={{header|Perl}}==
Line 904 ⟶ 897:
{{libheader|DOME}}
Curiously, this can only be done at present from a DOME program. A minimal script to do it would be:
<syntaxhighlight lang="ecmascriptwren">import "io" for FileSystem
 
class Main {
Line 920 ⟶ 913:
var Game = Main.new()</syntaxhighlight>
<br>
However, this functionality willis expected to be added to Wren-cli whenin versionthe 0.4.0next is officially releasedversion. The code needed will be as follows:
<syntaxhighlight lang="ecmascriptwren">import "io" for Directory
 
Directory.create("path/to/dir")</syntaxhighlight>
9,476

edits