June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View 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;
}

View file

@ -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

View 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();
}
}
}

View file

@ -0,0 +1 @@
mkpath("/tmp/unusefuldir/helloworld.d/test123")

View 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

View file

@ -0,0 +1,5 @@
class Program {
function : Main(args : String[]) ~ Nil {
System.IO.File.Directory->CreatePath("your/path/name")->PrintLine();
}
}