Makes sure the directory name exists and returns whether it does afterwards: an existing directory is a success, a file
of that name or (without recursive) a missing parent is a failure. With recursive, missing parents are created too.
Both / and \ work as separators.
make_directory_if_it_does_not_exist :: (
name: string,
recursive := false
) -> directory_now_exists: bool
Parameters
- name: string
- recursive := false
Returns
- directory_now_exists: bool
#import "Extensions/Environment";
base := environment_variable("TMPDIR");
if base == "" base = environment_variable("TEMP");
if base == "" base = "/tmp";
root := tprint("%/jai-doc-make-directory", base);
leaf := tprint("%/a/b", root);
defer {
delete_directory(leaf);
delete_directory(tprint("%/a", root));
delete_directory(root);
}
assert(!make_directory_if_it_does_not_exist(leaf)); // the parents are missing
assert(make_directory_if_it_does_not_exist(leaf, recursive = true));
assert(make_directory_if_it_does_not_exist(leaf)); // already thereDoesn't run in the browser (only on windows).