ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
pm_sysPath::isFailedMakeDir Interface Reference

Generate and return .true. if the attempt to create the requested directory path fails, otherwise return .false..
More...

Detailed Description

Generate and return .true. if the attempt to create the requested directory path fails, otherwise return .false..

The requested (potentially nested) directory is generated by first identifying the processor shell type (CMD, PowerShell, Bash, csh, zsh, ...) and then calling the runtime system shell via the Fortran intrinsic subroutine execute_command_line() to invoke mkdir shell command with appropriate flags.
Consequently, this procedure should function as expected in Windows CMD, PowerShell, and POSIX-compatible (Unix-like) shells.

Why not use the C library mkdir()?
While the C interface is nice and simple, it does not create nested directories, which leads to complications.
In the end, a Fortran-based solution was deemed more appropriate than calling the C libraries on different platforms.
The procedures under this generic interface open a subprocess to call the shell command mkdir to achieve the goal.
This is likely less efficient, but has the benefit of automatically enabling the creation of the nested directories without the need to process and split the input path into multiple directories.

Parameters
[in]path: The input scalar character of default kind SK containing a POSIX-style or Windows-style path.
[in]wait: The input scalar logical of default kind LK with the same functionality as the wait argument of the Fortran intrinsic execute_command_line().
  1. If .true., the procedure will wait for the mkdir action to terminate before returning the control to the Fortran program.
  2. Otherwise, the process of making the new directory will be done asynchronously.
(optional, default = .true.)
[in]ntry: The input scalar positive integer of default kind IK representing the number of times the requested action should be attempted.
Multiple tries are particularly useful on Windows platforms where applications take the ownership of a particular resource on the system and may not allow other applications to utilize the resource.
For example, Dropbox is a well-known example of an application that blocks any other applications from making any changes to a specific path with which it is working, preventing any manipulation of the path by other applications.
(optional, default = 1)
[in,out]errmsg: The input/output scalar character of default kind SK of arbitrary length type parameter.
If present and an error occurs, it is assigned an explanatory message describing the nature of the error that has occurred.
If the length of errmsg is too short for the output error message, the message tail will be clipped as needed.
A length of 2047 characters for errmsg is likely enough to capture most error messages in full.
(optional. If missing, no error message will be output.)
Returns
failed : The output scalar logical of default kind LK. It is .true. if and only if an error occurs while creating the requested directory.
This includes the possibility of the input directory path not being detected on the system after making it (only if wait = .true.).


Possible calling interfaces

use pm_kind, only: LK
logical(LK) :: failed
failed = isFailedMakeDir(path, wait = wait, ntry = ntry, errmsg = errmsg)
Generate and return .true. if the attempt to create the requested directory path fails,...
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
This module contains classes and procedures for manipulating system file/folder paths.
Definition: pm_sysPath.F90:274
Warning
Note that this procedure does not verify the conformance of the input path to the naming conventions of the current processor shell. For example,
  1. if the shell is POSIX-conforming, then the path is expected to conform to the POSIX conventions.
  2. if the shell is Windows CMD or PowerShell, the path is expected to conform to the Windows conventions.
The procedures of this generic interface interpret the input path verbatim (as is).
This is done to minimize security vulnerabilities and to properly handle the presence of whitespace or other potentially problematic characters.
Illegal characters in paths on Windows.
On Windows platforms with CMD or PowerShell runtime shell, this procedure returns .true. indicating failure if the input path contains Windows reserved characters or names that are illegal in paths.
These include Windows device names WINDOWS_RESERVED_DEVICE_NAME or Windows reserved characters WINDOWS_RESERVED_STR.
The input path must not exist prior to calling isFailedMakeDir.
This procedure does not check the existence of the input directory path.
Consequently, if it already exists, it may lead to a runtime error.
The existence of the input path can be readily checked via idsir.
Asynchronous directory creation.
Note that even if the processor supports asynchronous command execution (wait = .false.), there is no mechanism provided for finding out later whether the command being executed asynchronously has terminated or what its exit status exitstat was.
Nested directory creation when the shell type cannot be identified.
If the procedure cannot identify the runtime system shell, then it simply resorts to calling the mkdir command that is recognized by almost all shells, albeit without adding any flags for creating nested directories.
In such a scenario, the nested directory generation might fail if the shell requires mkdir with specific flags, or other commands.
The input ntry must be a positive (non-zero) integer.
This condition is verified only if the library is built with the preprocessor macro CHECK_ENABLED=1.
Remarks
The procedures under discussion are impure.
This procedure automatically generates nested directories if needed.
See also
getPathNew
getPathPosix
setPathPosix
getPathWindows
setPathWindows
isFailedGetDirTemp
isFailedMakeDirTemp
getPathHostNameIndex


Example usage

1program example
2
3 use pm_kind, only: LK, IK, SK
4 use pm_io, only: display_type
6
7 implicit none
8
9 character(:, SK), allocatable :: cpath
10
11 type(display_type) :: disp
12 disp = display_type(file = "main.out.F90")
13
14 call disp%skip()
15 call disp%show("cpath = getPathNew() ! define a random unique path name.")
16 cpath = getPathNew()
17 call disp%show("cpath")
18 call disp%show( cpath , deliml = SK_"""" )
19 call disp%show("isDir(cpath)")
20 call disp%show( isDir(cpath) )
21 call disp%show("isFailedMakeDir(cpath)")
22 call disp%show( isFailedMakeDir(cpath) )
23 call disp%show("isDir(cpath)")
24 call disp%show( isDir(cpath) )
25 call disp%skip()
26
27 call disp%skip()
28 call disp%show("cpath = getPathNew(dir = getPathNew())) ! define a random unique **nested** path name.")
29 cpath = getPathNew(dir = getPathNew())
30 call disp%show("cpath")
31 call disp%show( cpath , deliml = SK_"""" )
32 call disp%show("isDir(cpath)")
33 call disp%show( isDir(cpath) )
34 call disp%show("isFailedMakeDir(cpath)")
35 call disp%show( isFailedMakeDir(cpath) )
36 call disp%show("isDir(cpath)")
37 call disp%show( isDir(cpath) )
38 call disp%skip()
39
40end program example
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11726
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11508
Generate and return the directory separator symbol based on the runtime system shell.
Generate and return a unique (directory or file) path name in the specified directory or the default ...
Generate and return .true. is the input path is an extant system directory, otherwise return ....
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
Definition: pm_io.F90:11393
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
Definition: pm_kind.F90:540
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Definition: pm_kind.F90:539
Generate and return an object of type display_type.
Definition: pm_io.F90:10282

Example Unix compile command via Intel ifort compiler
1#!/usr/bin/env sh
2rm main.exe
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example Windows Batch compile command via Intel ifort compiler
1del main.exe
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
4main.exe

Example Unix / MinGW compile command via GNU gfortran compiler
1#!/usr/bin/env sh
2rm main.exe
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example output
1
2cpath = getPathNew() ! define a random unique path name.
3cpath
4"new_20240822_211527_382_pid_1"
5isDir(cpath)
6F
8F
9isDir(cpath)
10T
11
12
13cpath = getPathNew(dir = getPathNew())) ! define a random unique **nested** path name.
14cpath
15"new_20240822_211527_387_pid_1/new_20240822_211527_388_pid_1"
16isDir(cpath)
17F
18isFailedMakeDir(cpath)
19F
20isDir(cpath)
21T
22
23
Test:
test_pm_sysPath
Todo:
Normal Priority: The current Fortran standard 202x does not allow passing characters of non-default kind to the intrinsic Fortran statements and procedures.
This generic interface should be extended to in the future to support non-default character kinds when they fully supported by the Fortran intrinsic procedures.


Final Remarks


If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.

  1. If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
  2. If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.

This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.

Author:
Amir Shahmoradi, Tuesday March 7, 2017, 3:09 AM, Institute for Computational Engineering and Sciences (ICES), The University of Texas at Austin

Definition at line 3225 of file pm_sysPath.F90.


The documentation for this interface was generated from the following file: