Make directory path: Difference between revisions

Added Lua version
(Added Julia language)
(Added Lua version)
Line 239:
Directory path was created successfully
</pre>
 
=={{header|Lua}}==
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.
<lang Lua>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</lang>
Note that attempting to run lfs.mkdir for a path that already exists writes no changes to disk and returns nil.
 
=={{header|Mathematica}}==
Anonymous user