2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,3 +1,4 @@
|
|||
;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.
|
||||
|
|
@ -7,3 +8,4 @@ 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>
|
||||
|
|
|
|||
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)
|
||||
}
|
||||
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;
|
||||
}
|
||||
18
Task/Make-directory-path/NewLISP/make-directory-path.newlisp
Normal file
18
Task/Make-directory-path/NewLISP/make-directory-path.newlisp
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)
|
||||
|
|
@ -0,0 +1 @@
|
|||
mkdir 'path/to/dir'
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
for [\,] $*SPEC.splitdir("../path/to/dir") -> @path {
|
||||
mkdir $_ unless .e given $*SPEC.catdir(@path).IO;
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
mkpath 'path/to/dir'
|
||||
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
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
/*REXX program creates a directory and all its parent paths as necessary*/
|
||||
trace off /*suppress possible warning msgs.*/
|
||||
dPath = 'path\to\dir'
|
||||
'MKDIR' dPath "2>nul" /*alias could be used: MD Dpath */
|
||||
/*stick a fork in it, we're done.*/
|
||||
/*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.*/
|
||||
|
|
|
|||
10
Task/Make-directory-path/Run-BASIC/make-directory-path.run
Normal file
10
Task/Make-directory-path/Run-BASIC/make-directory-path.run
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue