Jump to content

Make directory path: Difference between revisions

Use functions from osfiles.s7i
m (→‎{{header|Wren}}: Changed to Wren S/H (future CLI version))
(Use functions from osfiles.s7i)
 
Line 842:
 
=={{header|Seed7}}==
The library [http://seed7.sourceforge.net/libraries/cli_cmdsosfiles.htm cli_cmdsosfiles.s7i]
defines the functions [https://seed7.sourceforge.net/libraries/osfiles.htm#makeParentDirs(in_string) makeParentDirs], which creates the parent directories of the given path and [https://seed7.sourceforge.net/libraries/osfiles.htm#makeDir(in_string) makeDir], which creates a new directory. If the parent directory already exists a call of makeDir is sufficient and makeParentDirs is not necessary. The functions from osfiles.s7i use the [https://seed7.sourceforge.net/manual/os.htm#Standard_path_representation standard path representation] (the path delimiter is / and no drive letters exist). The function [https://seed7.sourceforge.net/libraries/osfiles.htm#convDosPath(in_string) convDosPath] converts a path with backslashes and drive letters to the standard path representation.
defines the function doMkdirCmd, which is used below.
 
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "cli_cmdsosfiles.s7i";
 
const proc: mainmakeDirectoryPath (in string: dirPath) is func
begin
makeParentDirs(dirPath);
doMkdirCmd(argv(PROGRAM), TRUE);
if fileTypeSL(dirPath) <> FILE_DIR then
end func;</syntaxhighlight>
makeDir(dirPath);
 
end if;
The library cli_cmds.s7i defines also
end func;
[http://seed7.sourceforge.net/libraries/cli_cmds.htm#doMkdir%28inout_string%29 doMkdir] (Make directories like the Unix mkdir command)
and [http://seed7.sourceforge.net/libraries/cli_cmds.htm#doMd%28inout_string%29 doMd] (Make directories like the DOS md command).
This functions read the parameters and options from a string.
The reading is done according to Unix respectively DOS/Windows rules.
The function doMkdir is used in the alternate solution below:
 
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "cli_cmds.s7i";
 
const proc: main is func
local
var string: parameters is "";
begin
parameters :=if joinlength(argv(PROGRAM),) "<> ");1 then
writeln("usage: makeDirectoryPath path");
doMkdir(parameters);
elsif succeeds(makeDirectoryPath(convDosPath(argv(PROGRAM)[1]))) then
writeln("Directory path now exists");
else
writeln("Failed to create directory path");
end if;
end func;</syntaxhighlight>
 
29

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.