Make directory path: Difference between revisions
Content added Content deleted
(Added Kotlin) |
|||
Line 272: | Line 272: | ||
mkdir $_ unless .e given $*SPEC.catdir(@path).IO; |
mkdir $_ unless .e given $*SPEC.catdir(@path).IO; |
||
}</lang> |
}</lang> |
||
=={{header|Phix}}== |
|||
There's a builtin for that |
|||
<lang Phix>if not create_directory("myapp/interface/letters") then |
|||
crash("Filesystem problem - could not create the new folder") |
|||
end if</lang> |
|||
The implementation in builtins/pfile.e is as follows (see there for initf() etc): |
|||
<lang Phix>global function create_directory(string name, integer mode=0o700, bool make_parent=1) |
|||
bool ret |
|||
if not finit then initf() end if |
|||
if length(name)=0 then |
|||
?9/0 |
|||
end if |
|||
name = get_proper_path(name) |
|||
-- Remove any trailing slash. |
|||
if name[$]=SLASH then |
|||
name = name[1..$-1] |
|||
end if |
|||
if make_parent then |
|||
integer pos = rfind(SLASH, name) |
|||
if pos!=0 then |
|||
string parent = name[1..pos-1] |
|||
if file_exists(parent) then |
|||
if file_type(parent)!=FILETYPE_DIRECTORY then ?9/0 end if |
|||
else |
|||
if not create_directory(parent, mode, make_parent) then |
|||
return 0 |
|||
end if |
|||
end if |
|||
end if |
|||
end if |
|||
if platform()=LINUX then |
|||
ret = not c_func(xCreateDirectory, {name, mode}) |
|||
elsif platform()=WINDOWS then |
|||
ret = c_func(xCreateDirectory, {name, 0}) |
|||
end if |
|||
return ret |
|||
end function</lang> |
|||
Of course you could also use system("mkdir -p path/to-dir") or whatever. |
|||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |