Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
3
Task/Make-directory-path/00-META.yaml
Normal file
3
Task/Make-directory-path/00-META.yaml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
from: http://rosettacode.org/wiki/Make_directory_path
|
||||
note: File System Operations
|
||||
12
Task/Make-directory-path/00-TASK.txt
Normal file
12
Task/Make-directory-path/00-TASK.txt
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
;Task:
|
||||
Create a directory and any missing parents.
|
||||
|
||||
This task is named after the posix <code>[http://www.unix.com/man-page/POSIX/0/mkdir/ mkdir -p]</code> command, and several libraries which implement the same behavior.
|
||||
|
||||
Please implement a function of a single path string (for example <code>./path/to/dir</code>) which has the above side-effect.
|
||||
If the directory already exists, return successfully.
|
||||
Ideally implementations will work equally well cross-platform (on windows, linux, and OS X).
|
||||
|
||||
It's likely that your language implements such a function as part of its standard library. If so, please also show how such a function would be implemented.
|
||||
<br><br>
|
||||
|
||||
1
Task/Make-directory-path/11l/make-directory-path.11l
Normal file
1
Task/Make-directory-path/11l/make-directory-path.11l
Normal file
|
|
@ -0,0 +1 @@
|
|||
fs:create_dirs(path)
|
||||
14
Task/Make-directory-path/AWK/make-directory-path.awk
Normal file
14
Task/Make-directory-path/AWK/make-directory-path.awk
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# syntax: GAWK -f MAKE_DIRECTORY_PATH.AWK path ...
|
||||
BEGIN {
|
||||
for (i=1; i<=ARGC-1; i++) {
|
||||
path = ARGV[i]
|
||||
msg = (make_dir_path(path) == 0) ? "created" : "exists"
|
||||
printf("'%s' %s\n",path,msg)
|
||||
}
|
||||
exit(0)
|
||||
}
|
||||
function make_dir_path(path, cmd) {
|
||||
# cmd = sprintf("mkdir -p '%s'",path) # Unix
|
||||
cmd = sprintf("MKDIR \"%s\" 2>NUL",path) # MS-Windows
|
||||
return system(cmd)
|
||||
}
|
||||
17
Task/Make-directory-path/Ada/make-directory-path.ada
Normal file
17
Task/Make-directory-path/Ada/make-directory-path.ada
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
with Ada.Command_Line;
|
||||
with Ada.Directories;
|
||||
with Ada.Text_IO;
|
||||
|
||||
procedure Make_Directory_Path is
|
||||
begin
|
||||
if Ada.Command_Line.Argument_Count /= 1 then
|
||||
Ada.Text_IO.Put_Line ("Usage: make_directory_path <path/to/dir>");
|
||||
return;
|
||||
end if;
|
||||
|
||||
declare
|
||||
Path : String renames Ada.Command_Line.Argument (1);
|
||||
begin
|
||||
Ada.Directories.Create_Path (Path);
|
||||
end;
|
||||
end Make_Directory_Path;
|
||||
21
Task/Make-directory-path/Aime/make-directory-path.aime
Normal file
21
Task/Make-directory-path/Aime/make-directory-path.aime
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
void
|
||||
mkdirp(text path)
|
||||
{
|
||||
list l;
|
||||
text p, s;
|
||||
|
||||
file().b_affix(path).news(l, 0, 0, "/");
|
||||
|
||||
for (, s in l) {
|
||||
p = p + s + "/";
|
||||
trap_q(mkdir, p, 00755);
|
||||
}
|
||||
}
|
||||
|
||||
integer
|
||||
main(void)
|
||||
{
|
||||
mkdirp("./path/to/dir");
|
||||
|
||||
0;
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
use framework "Foundation"
|
||||
use scripting additions
|
||||
|
||||
|
||||
-- createOrFindDirectoryMay :: Bool -> FilePath -> Maybe IO ()
|
||||
on createOrFindDirectoryMay(fp)
|
||||
createDirectoryIfMissingMay(true, fp)
|
||||
end createOrFindDirectoryMay
|
||||
|
||||
|
||||
-- createDirectoryIfMissingMay :: Bool -> FilePath -> Maybe IO ()
|
||||
on createDirectoryIfMissingMay(blnParents, fp)
|
||||
if doesPathExist(fp) then
|
||||
nothing("Directory already exists: " & fp)
|
||||
else
|
||||
set e to reference
|
||||
set ca to current application
|
||||
set oPath to (ca's NSString's stringWithString:(fp))'s ¬
|
||||
stringByStandardizingPath
|
||||
set {bool, nse} to ca's NSFileManager's ¬
|
||||
defaultManager's createDirectoryAtPath:(oPath) ¬
|
||||
withIntermediateDirectories:(blnParents) ¬
|
||||
attributes:(missing value) |error|:(e)
|
||||
if bool then
|
||||
just(fp)
|
||||
else
|
||||
nothing((localizedDescription of nse) as string)
|
||||
end if
|
||||
end if
|
||||
end createDirectoryIfMissingMay
|
||||
|
||||
-- TEST ----------------------------------------------------------------------
|
||||
on run
|
||||
|
||||
createOrFindDirectoryMay("~/Desktop/Notes/today")
|
||||
|
||||
end run
|
||||
|
||||
-- GENERIC FUNCTIONS ---------------------------------------------------------
|
||||
|
||||
-- doesPathExist :: FilePath -> IO Bool
|
||||
on doesPathExist(strPath)
|
||||
set ca to current application
|
||||
ca's NSFileManager's defaultManager's ¬
|
||||
fileExistsAtPath:((ca's NSString's ¬
|
||||
stringWithString:strPath)'s ¬
|
||||
stringByStandardizingPath)
|
||||
end doesPathExist
|
||||
|
||||
-- just :: a -> Just a
|
||||
on just(x)
|
||||
{nothing:false, just:x}
|
||||
end just
|
||||
|
||||
-- nothing :: () -> Nothing
|
||||
on nothing(msg)
|
||||
{nothing:true, msg:msg}
|
||||
end nothing
|
||||
|
|
@ -0,0 +1 @@
|
|||
write.directory "path/to/some/directory" ø
|
||||
26
Task/Make-directory-path/C++/make-directory-path.cpp
Normal file
26
Task/Make-directory-path/C++/make-directory-path.cpp
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#include <filesystem>
|
||||
#include <iostream>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if(argc != 2)
|
||||
{
|
||||
std::cout << "usage: mkdir <path>\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
fs::path pathToCreate(argv[1]);
|
||||
|
||||
if (fs::exists(pathToCreate))
|
||||
return 0;
|
||||
|
||||
if (fs::create_directories(pathToCreate))
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
std::cout << "couldn't create directory: " << pathToCreate.string() << std::endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
1
Task/Make-directory-path/C-sharp/make-directory-path.cs
Normal file
1
Task/Make-directory-path/C-sharp/make-directory-path.cs
Normal file
|
|
@ -0,0 +1 @@
|
|||
System.IO.Directory.CreateDirectory(path)
|
||||
32
Task/Make-directory-path/C/make-directory-path.c
Normal file
32
Task/Make-directory-path/C/make-directory-path.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <libgen.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
char *str, *s;
|
||||
struct stat statBuf;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf (stderr, "usage: %s <path>\n", basename (argv[0]));
|
||||
exit (1);
|
||||
}
|
||||
s = argv[1];
|
||||
while ((str = strtok (s, "/")) != NULL) {
|
||||
if (str != s) {
|
||||
str[-1] = '/';
|
||||
}
|
||||
if (stat (argv[1], &statBuf) == -1) {
|
||||
mkdir (argv[1], 0);
|
||||
} else {
|
||||
if (! S_ISDIR (statBuf.st_mode)) {
|
||||
fprintf (stderr, "couldn't create directory %s\n", argv[1]);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
s = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
5
Task/Make-directory-path/Clojure/make-directory-path.clj
Normal file
5
Task/Make-directory-path/Clojure/make-directory-path.clj
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
(defn mkdirp [path]
|
||||
(let [dir (java.io.File. path)]
|
||||
(if (.exists dir)
|
||||
true
|
||||
(.mkdirs dir))))
|
||||
|
|
@ -0,0 +1 @@
|
|||
(ensure-directories-exist "your/path/name")
|
||||
29
Task/Make-directory-path/D/make-directory-path.d
Normal file
29
Task/Make-directory-path/D/make-directory-path.d
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import std.stdio;
|
||||
|
||||
void main() {
|
||||
makeDir("parent/test");
|
||||
}
|
||||
|
||||
/// Manual implementation of what mkdirRecurse in std.file does.
|
||||
void makeDir(string path) out {
|
||||
import std.exception : enforce;
|
||||
import std.file : exists;
|
||||
enforce(path.exists, "Failed to create the requested directory.");
|
||||
} body {
|
||||
import std.array : array;
|
||||
import std.file;
|
||||
import std.path : pathSplitter, chainPath;
|
||||
|
||||
auto workdir = "";
|
||||
foreach (dir; path.pathSplitter) {
|
||||
workdir = chainPath(workdir, dir).array;
|
||||
if (workdir.exists) {
|
||||
if (!workdir.isDir) {
|
||||
import std.conv : text;
|
||||
throw new FileException(text("The file ", workdir, " in the path ", path, " is not a directory."));
|
||||
}
|
||||
} else {
|
||||
workdir.mkdir();
|
||||
}
|
||||
}
|
||||
}
|
||||
24
Task/Make-directory-path/Delphi/make-directory-path.delphi
Normal file
24
Task/Make-directory-path/Delphi/make-directory-path.delphi
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
program Make_directory_path;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
uses
|
||||
System.SysUtils,
|
||||
System.IOUtils;
|
||||
|
||||
const
|
||||
Path1 = '.\folder1\folder2\folder3'; // windows relative path (others OS formats are acepted)
|
||||
Path2 = 'folder4\folder5\folder6';
|
||||
|
||||
begin
|
||||
// "ForceDirectories" work with relative path if start with "./"
|
||||
if ForceDirectories(Path1) then
|
||||
Writeln('Created "', path1, '" sucessfull.');
|
||||
|
||||
// "TDirectory.CreateDirectory" work with any path format
|
||||
// but don't return sucess, requere "TDirectory.Exists" to check
|
||||
TDirectory.CreateDirectory(Path2);
|
||||
if TDirectory.Exists(Path2) then
|
||||
Writeln('Created "', path2, '" sucessfull.');
|
||||
Readln;
|
||||
end.
|
||||
1
Task/Make-directory-path/ERRE/make-directory-path.erre
Normal file
1
Task/Make-directory-path/ERRE/make-directory-path.erre
Normal file
|
|
@ -0,0 +1 @@
|
|||
OS_MKDIR("C:\EXAMPLES\03192015")
|
||||
|
|
@ -0,0 +1 @@
|
|||
File.mkdir_p("./path/to/dir")
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
USE: io.directories
|
||||
"path/to/dir" make-directories
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
USING: combinators.short-circuit io.backend io.files
|
||||
io.pathnames kernel sequences ;
|
||||
IN: io.directories
|
||||
: make-directories ( path -- )
|
||||
normalize-path trim-tail-separators dup
|
||||
{ [ "." = ] [ root-directory? ] [ empty? ] [ exists? ] } 1||
|
||||
[ make-parent-directories dup make-directory ] unless drop ;
|
||||
17
Task/Make-directory-path/FreeBASIC/make-directory-path.basic
Normal file
17
Task/Make-directory-path/FreeBASIC/make-directory-path.basic
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#ifdef __FB_WIN32__
|
||||
Dim pathname As String = "Ring\docs"
|
||||
#else
|
||||
Dim pathname As String = "Ring/docs"
|
||||
#endif
|
||||
|
||||
Dim As String mkpathname = "mkdir " & pathname
|
||||
Dim result As Long = Shell (mkpathname)
|
||||
|
||||
If result = 0 Then
|
||||
Print "Created the directory..."
|
||||
Chdir(pathname)
|
||||
Print Curdir
|
||||
Else
|
||||
Print "error: unable to create folder " & pathname & " in the current path."
|
||||
End If
|
||||
Sleep
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
Public Sub Form_Open()
|
||||
|
||||
If Not Exist(User.home &/ "TestFolder") Then Mkdir User.Home &/ "TestFolder"
|
||||
|
||||
End
|
||||
1
Task/Make-directory-path/Go/make-directory-path.go
Normal file
1
Task/Make-directory-path/Go/make-directory-path.go
Normal file
|
|
@ -0,0 +1 @@
|
|||
os.MkdirAll("/tmp/some/path/to/dir", 0770)
|
||||
7
Task/Make-directory-path/Haskell/make-directory-path.hs
Normal file
7
Task/Make-directory-path/Haskell/make-directory-path.hs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import System.Directory (createDirectory, setCurrentDirectory)
|
||||
import Data.List.Split (splitOn)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
let path = splitOn "/" "path/to/dir"
|
||||
mapM_ (\x -> createDirectory x >> setCurrentDirectory x) path
|
||||
2
Task/Make-directory-path/J/make-directory-path-1.j
Normal file
2
Task/Make-directory-path/J/make-directory-path-1.j
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
require 'general/dirutils'
|
||||
pathcreate '/tmp/some/path/to/dir'
|
||||
17
Task/Make-directory-path/J/make-directory-path-2.j
Normal file
17
Task/Make-directory-path/J/make-directory-path-2.j
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
pathcreate=: monad define
|
||||
todir=. termsep_j_ jpathsep y
|
||||
todirs=. }. ,each /\ <;.2 todir NB. base dirs
|
||||
msk=. -.direxist todirs NB. 1 for each non-existing dir
|
||||
msk=. 0 (i. msk i: 0)}msk
|
||||
dircreate msk#todirs NB. create non-existing base dirs
|
||||
)
|
||||
|
||||
dircreate=: monad define
|
||||
y=. boxxopen y
|
||||
msk=. -.direxist y
|
||||
if. ''-:$msk do. msk=. (#y)#msk end.
|
||||
res=. 1!:5 msk#y
|
||||
msk #inv ,res
|
||||
)
|
||||
|
||||
direxist=: 2 = ftype&>@:boxopen
|
||||
14
Task/Make-directory-path/Java/make-directory-path.java
Normal file
14
Task/Make-directory-path/Java/make-directory-path.java
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import java.io.File;
|
||||
|
||||
public interface Test {
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
File f = new File("C:/parent/test");
|
||||
if (f.mkdirs())
|
||||
System.out.println("path successfully created");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
27
Task/Make-directory-path/JavaScript/make-directory-path.js
Normal file
27
Task/Make-directory-path/JavaScript/make-directory-path.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
|
||||
function mkdirp (p, cb) {
|
||||
cb = cb || function () {};
|
||||
p = path.resolve(p);
|
||||
|
||||
fs.mkdir(p, function (er) {
|
||||
if (!er) {
|
||||
return cb(null);
|
||||
}
|
||||
switch (er.code) {
|
||||
case 'ENOENT':
|
||||
// The directory doesn't exist. Make its parent and try again.
|
||||
mkdirp(path.dirname(p), function (er) {
|
||||
if (er) cb(er);
|
||||
else mkdirp(p, cb);
|
||||
});
|
||||
break;
|
||||
|
||||
// In the case of any other error, something is borked.
|
||||
default:
|
||||
cb(er);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
1
Task/Make-directory-path/Julia/make-directory-path.julia
Normal file
1
Task/Make-directory-path/Julia/make-directory-path.julia
Normal file
|
|
@ -0,0 +1 @@
|
|||
mkpath("/tmp/unusefuldir/helloworld.d/test123")
|
||||
10
Task/Make-directory-path/Kotlin/make-directory-path.kotlin
Normal file
10
Task/Make-directory-path/Kotlin/make-directory-path.kotlin
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// version 1.0.6
|
||||
|
||||
import java.io.File
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
// using built-in mkdirs() method
|
||||
val success = File("./path/to/dir").mkdirs()
|
||||
if (success) println("Directory path was created successfully")
|
||||
else println("Failed to create directory path")
|
||||
}
|
||||
11
Task/Make-directory-path/Lua/make-directory-path.lua
Normal file
11
Task/Make-directory-path/Lua/make-directory-path.lua
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
require("lfs")
|
||||
|
||||
function mkdir (path)
|
||||
local sep, pStr = package.config:sub(1, 1), ""
|
||||
for dir in path:gmatch("[^" .. sep .. "]+") do
|
||||
pStr = pStr .. dir .. sep
|
||||
lfs.mkdir(pStr)
|
||||
end
|
||||
end
|
||||
|
||||
mkdir("C:\\path\\to\\dir") -- Quoting backslashes requires escape sequence
|
||||
|
|
@ -0,0 +1 @@
|
|||
mkdirp[path_] := Quiet[CreateDirectory[path,{CreateIntermediateDirectories->True}],{CreateDirectory::filex}]
|
||||
18
Task/Make-directory-path/NewLISP/make-directory-path.l
Normal file
18
Task/Make-directory-path/NewLISP/make-directory-path.l
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
(define (mkdir-p mypath)
|
||||
(if (= "/" (mypath 0)) ;; Abs or relative path?
|
||||
(setf /? "/")
|
||||
(setf /? "")
|
||||
)
|
||||
(setf path-components (clean empty? (parse mypath "/"))) ;; Split path and remove empty elements
|
||||
(for (x 0 (length path-components))
|
||||
(setf walking-path (string /? (join (slice path-components 0 (+ 1 x)) "/")))
|
||||
(make-dir walking-path)
|
||||
)
|
||||
)
|
||||
|
||||
;; Using user-made function...
|
||||
(mkdir-p "/tmp/rosetta/test1")
|
||||
|
||||
;; ... or calling OS command directly.
|
||||
(! "mkdir -p /tmp/rosetta/test2")
|
||||
(exit)
|
||||
7
Task/Make-directory-path/Nim/make-directory-path.nim
Normal file
7
Task/Make-directory-path/Nim/make-directory-path.nim
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import os
|
||||
|
||||
try:
|
||||
createDir("./path/to/dir")
|
||||
echo "Directory now exists."
|
||||
except OSError:
|
||||
echo "Failed to create the directory."
|
||||
14
Task/Make-directory-path/OCaml/make-directory-path.ocaml
Normal file
14
Task/Make-directory-path/OCaml/make-directory-path.ocaml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#load "unix.cma"
|
||||
|
||||
let mkdir_p ~path ~perms =
|
||||
let ps = String.split_on_char '/' path in
|
||||
let rec aux acc = function [] -> ()
|
||||
| p::ps ->
|
||||
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
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
class Program {
|
||||
function : Main(args : String[]) ~ Nil {
|
||||
System.IO.File.Directory->CreatePath("your/path/name")->PrintLine();
|
||||
}
|
||||
}
|
||||
3
Task/Make-directory-path/Perl/make-directory-path.pl
Normal file
3
Task/Make-directory-path/Perl/make-directory-path.pl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
use File::Path qw(make_path);
|
||||
|
||||
make_path('path/to/dir')
|
||||
6
Task/Make-directory-path/Phix/make-directory-path-1.phix
Normal file
6
Task/Make-directory-path/Phix/make-directory-path-1.phix
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
(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;">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: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<!--
|
||||
41
Task/Make-directory-path/Phix/make-directory-path-2.phix
Normal file
41
Task/Make-directory-path/Phix/make-directory-path-2.phix
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
-->
|
||||
<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;">if</span> <span style="color: #008080;">not</span> <span style="color: #000000;">finit</span> <span style="color: #008080;">then</span> <span style="color: #000000;">initf</span><span style="color: #0000FF;">()</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
|
||||
<span style="color: #7060A8;">assert</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">name</span><span style="color: #0000FF;">)!=</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #000000;">name</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">get_proper_path</span><span style="color: #0000FF;">(</span><span style="color: #000000;">name</span><span style="color: #0000FF;">)</span>
|
||||
|
||||
<span style="color: #000080;font-style:italic;">-- Remove any trailing slash.</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #000000;">name</span><span style="color: #0000FF;">[$]=</span><span style="color: #004600;">SLASH</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #000000;">name</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">name</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">..$-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
|
||||
<span style="color: #008080;">if</span> <span style="color: #000000;">make_parent</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #004080;">integer</span> <span style="color: #000000;">pos</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">rfind</span><span style="color: #0000FF;">(</span><span style="color: #004600;">SLASH</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">name</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #000000;">pos</span><span style="color: #0000FF;">!=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #004080;">string</span> <span style="color: #000000;">parent</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">name</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">..</span><span style="color: #000000;">pos</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #7060A8;">file_exists</span><span style="color: #0000FF;">(</span><span style="color: #000000;">parent</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #7060A8;">assert</span><span style="color: #0000FF;">(</span><span style="color: #000000;">file_type</span><span style="color: #0000FF;">(</span><span style="color: #000000;">parent</span><span style="color: #0000FF;">)==</span><span style="color: #004600;">FILETYPE_DIRECTORY</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">else</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: #000000;">parent</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">mode</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">make_parent</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #000000;">0</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>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
|
||||
<span style="color: #004080;">bool</span> <span style="color: #000000;">ret</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()=</span><span style="color: #004600;">LINUX</span> <span style="color: #008080;">then</span>
|
||||
|
||||
<span style="color: #000000;">ret</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">not</span> <span style="color: #7060A8;">c_func</span><span style="color: #0000FF;">(</span><span style="color: #000000;">xCreateDirectory</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">name</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">mode</span><span style="color: #0000FF;">})</span>
|
||||
|
||||
<span style="color: #008080;">elsif</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()=</span><span style="color: #004600;">WINDOWS</span> <span style="color: #008080;">then</span>
|
||||
|
||||
<span style="color: #000000;">ret</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">c_func</span><span style="color: #0000FF;">(</span><span style="color: #000000;">xCreateDirectory</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">name</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">})</span>
|
||||
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</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>
|
||||
<!--
|
||||
1
Task/Make-directory-path/PicoLisp/make-directory-path.l
Normal file
1
Task/Make-directory-path/PicoLisp/make-directory-path.l
Normal file
|
|
@ -0,0 +1 @@
|
|||
(call "mkdir" "-p" "path/to/dir")
|
||||
|
|
@ -0,0 +1 @@
|
|||
New-Item -Path ".\path\to\dir" -ItemType Directory -ErrorAction SilentlyContinue
|
||||
23
Task/Make-directory-path/Python/make-directory-path-1.py
Normal file
23
Task/Make-directory-path/Python/make-directory-path-1.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
from errno import EEXIST
|
||||
from os import mkdir, curdir
|
||||
from os.path import split, exists
|
||||
|
||||
def mkdirp(path, mode=0777):
|
||||
head, tail = split(path)
|
||||
if not tail:
|
||||
head, tail = split(head)
|
||||
if head and tail and not exists(head):
|
||||
try:
|
||||
mkdirp(head, mode)
|
||||
except OSError as e:
|
||||
# be happy if someone already created the path
|
||||
if e.errno != EEXIST:
|
||||
raise
|
||||
if tail == curdir: # xxx/newdir/. exists if xxx/newdir exists
|
||||
return
|
||||
try:
|
||||
mkdir(path, mode)
|
||||
except OSError as e:
|
||||
# be happy if someone already created the path
|
||||
if e.errno != EEXIST:
|
||||
raise
|
||||
7
Task/Make-directory-path/Python/make-directory-path-2.py
Normal file
7
Task/Make-directory-path/Python/make-directory-path-2.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
def mkdirp(path):
|
||||
try:
|
||||
os.makedirs(path)
|
||||
except OSError as exc: # Python >2.5
|
||||
if exc.errno == errno.EEXIST and os.path.isdir(path):
|
||||
pass
|
||||
else: raise
|
||||
2
Task/Make-directory-path/Python/make-directory-path-3.py
Normal file
2
Task/Make-directory-path/Python/make-directory-path-3.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
def mkdirp(path):
|
||||
os.makedirs(path, exist_ok=True)
|
||||
7
Task/Make-directory-path/REXX/make-directory-path.rexx
Normal file
7
Task/Make-directory-path/REXX/make-directory-path.rexx
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
/*REXX program creates a directory (folder) and all its parent paths as necessary. */
|
||||
trace off /*suppress possible warning msgs.*/
|
||||
|
||||
dPath = 'path\to\dir' /*define directory (folder) path.*/
|
||||
|
||||
'MKDIR' dPath "2>nul" /*alias could be used: MD dPath */
|
||||
/*stick a fork in it, we're done.*/
|
||||
22
Task/Make-directory-path/Racket/make-directory-path.rkt
Normal file
22
Task/Make-directory-path/Racket/make-directory-path.rkt
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#lang racket
|
||||
(define path-str "/tmp/woo/yay")
|
||||
(define path/..-str "/tmp/woo")
|
||||
|
||||
;; clean up from a previous run
|
||||
(when (directory-exists? path-str)
|
||||
(delete-directory path-str)
|
||||
(delete-directory path/..-str))
|
||||
;; delete-directory/files could also be used -- but that requires goggles and rubber
|
||||
;; gloves to handle safely!
|
||||
|
||||
(define (report-path-exists)
|
||||
(printf "~s exists (as a directory?):~a~%~s exists (as a directory?):~a~%~%"
|
||||
path/..-str (directory-exists? path/..-str)
|
||||
path-str (directory-exists? path-str)))
|
||||
|
||||
(report-path-exists)
|
||||
|
||||
;; Really ... this is the only bit that matters!
|
||||
(make-directory* path-str)
|
||||
|
||||
(report-path-exists)
|
||||
1
Task/Make-directory-path/Raku/make-directory-path-1.raku
Normal file
1
Task/Make-directory-path/Raku/make-directory-path-1.raku
Normal file
|
|
@ -0,0 +1 @@
|
|||
mkdir 'path/to/dir'
|
||||
3
Task/Make-directory-path/Raku/make-directory-path-2.raku
Normal file
3
Task/Make-directory-path/Raku/make-directory-path-2.raku
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
for [\,] $*SPEC.splitdir("../path/to/dir") -> @path {
|
||||
mkdir $_ unless .e given $*SPEC.catdir(@path).IO;
|
||||
}
|
||||
11
Task/Make-directory-path/Ring/make-directory-path.ring
Normal file
11
Task/Make-directory-path/Ring/make-directory-path.ring
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
System("mkdir C:\Ring\docs")
|
||||
isdir("C:\Ring\docs")
|
||||
|
||||
see isdir("C:\Ring\docs") + nl
|
||||
func isdir cDir
|
||||
try
|
||||
dir(cDir)
|
||||
return true
|
||||
catch
|
||||
return false
|
||||
done
|
||||
2
Task/Make-directory-path/Ruby/make-directory-path.rb
Normal file
2
Task/Make-directory-path/Ruby/make-directory-path.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
require 'fileutils'
|
||||
FileUtils.mkdir_p("path/to/dir")
|
||||
10
Task/Make-directory-path/Run-BASIC/make-directory-path.basic
Normal file
10
Task/Make-directory-path/Run-BASIC/make-directory-path.basic
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
files #f, "c:\myDocs" ' check for directory
|
||||
if #f hasanswer() then
|
||||
if #f isDir() then ' is it a file or a directory
|
||||
print "A directory exist"
|
||||
else
|
||||
print "A file exist"
|
||||
end if
|
||||
else
|
||||
shell$("mkdir c:\myDocs" ' if not exist make a directory
|
||||
end if
|
||||
5
Task/Make-directory-path/Rust/make-directory-path.rust
Normal file
5
Task/Make-directory-path/Rust/make-directory-path.rust
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
use std::fs;
|
||||
|
||||
fn main() {
|
||||
fs::create_dir_all("./path/to/dir").expect("An Error Occured!")
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
new java.io.File("/path/to/dir").mkdirs
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
import java.io.File
|
||||
|
||||
def mkdirs(path: List[String]) = // return true if path was created
|
||||
path.tail.foldLeft(new File(path.head)){(a,b) => a.mkdir; new File(a,b)}.mkdir
|
||||
|
||||
mkdirs(List("/path", "to", "dir"))
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
$ include "seed7_05.s7i";
|
||||
include "cli_cmds.s7i";
|
||||
|
||||
const proc: main is func
|
||||
begin
|
||||
doMkdirCmd(argv(PROGRAM), TRUE);
|
||||
end func;
|
||||
10
Task/Make-directory-path/Seed7/make-directory-path-2.seed7
Normal file
10
Task/Make-directory-path/Seed7/make-directory-path-2.seed7
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
$ include "seed7_05.s7i";
|
||||
include "cli_cmds.s7i";
|
||||
|
||||
const proc: main is func
|
||||
local
|
||||
var string: parameters is "";
|
||||
begin
|
||||
parameters := join(argv(PROGRAM), " ");
|
||||
doMkdir(parameters);
|
||||
end func;
|
||||
1
Task/Make-directory-path/Sidef/make-directory-path.sidef
Normal file
1
Task/Make-directory-path/Sidef/make-directory-path.sidef
Normal file
|
|
@ -0,0 +1 @@
|
|||
Dir.new(Dir.cwd, "path", "to", "dir").make_path; # works cross-platform
|
||||
1
Task/Make-directory-path/Tcl/make-directory-path.tcl
Normal file
1
Task/Make-directory-path/Tcl/make-directory-path.tcl
Normal file
|
|
@ -0,0 +1 @@
|
|||
file mkdir ./path/to/dir
|
||||
|
|
@ -0,0 +1 @@
|
|||
function mkdirp() { mkdir -p "$1"; }
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
Module Module1
|
||||
|
||||
Sub Main()
|
||||
System.IO.Directory.CreateDirectory("some/where")
|
||||
End Sub
|
||||
|
||||
End Module
|
||||
15
Task/Make-directory-path/Wren/make-directory-path-1.wren
Normal file
15
Task/Make-directory-path/Wren/make-directory-path-1.wren
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import "io" for FileSystem
|
||||
|
||||
class Main {
|
||||
construct new() {}
|
||||
|
||||
init() {
|
||||
FileSystem.createDirectory("path/to/dir")
|
||||
}
|
||||
|
||||
update() {}
|
||||
|
||||
draw(alpha) {}
|
||||
}
|
||||
|
||||
var Game = Main.new()
|
||||
3
Task/Make-directory-path/Wren/make-directory-path-2.wren
Normal file
3
Task/Make-directory-path/Wren/make-directory-path-2.wren
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import "io" for Directory
|
||||
|
||||
Directory.create("path/to/dir")
|
||||
1
Task/Make-directory-path/Zkl/make-directory-path-1.zkl
Normal file
1
Task/Make-directory-path/Zkl/make-directory-path-1.zkl
Normal file
|
|
@ -0,0 +1 @@
|
|||
System.cmd("mkdir -p ../foo/bar")
|
||||
1
Task/Make-directory-path/Zkl/make-directory-path-2.zkl
Normal file
1
Task/Make-directory-path/Zkl/make-directory-path-2.zkl
Normal file
|
|
@ -0,0 +1 @@
|
|||
fcn mkdir(path) { System.cmd("mkdir -p "+path) }
|
||||
Loading…
Add table
Add a link
Reference in a new issue