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() .
-
If
.true. , the procedure will wait for the mkdir action to terminate before returning the control to the Fortran program.
-
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 ⛓
logical(LK) :: failed
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...
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
This module contains classes and procedures for manipulating system file/folder paths.
- 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,
- if the shell is POSIX-conforming, then the path is expected to conform to the POSIX conventions.
- 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
.
- See also
- getPathNew
getPathPosix
setPathPosix
getPathWindows
setPathWindows
isFailedGetDirTemp
isFailedMakeDirTemp
getPathHostNameIndex
Example usage ⛓
9 character(:, SK),
allocatable :: cpath
11 type(display_type) :: disp
15 call disp%show(
"cpath = getPathNew() ! define a random unique path name.")
18 call disp%show( cpath , deliml
= SK_
"""" )
21 call disp%show(
"isFailedMakeDir(cpath)")
28 call disp%show(
"cpath = getPathNew(dir = getPathNew())) ! define a random unique **nested** path name.")
31 call disp%show( cpath , deliml
= SK_
"""" )
34 call disp%show(
"isFailedMakeDir(cpath)")
This is a generic method of the derived type display_type with pass attribute.
This is a generic method of the derived type display_type with pass attribute.
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...
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Generate and return an object of type display_type.
Example Unix compile command via Intel ifort
compiler ⛓
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example Windows Batch compile command via Intel ifort
compiler ⛓
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
Example Unix / MinGW compile command via GNU gfortran
compiler ⛓
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example output ⛓
4"new_20241027_224347_218_pid_1"
15"new_20241027_224347_222_pid_1/new_20241027_224347_223_pid_1"
- 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.
-
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.
-
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.
- Copyright
- Computational Data Science Lab
- Author:
- Amir Shahmoradi, Tuesday March 7, 2017, 3:09 AM, Institute for Computational Engineering and Sciences (ICES), The University of Texas Austin
Definition at line 3225 of file pm_sysPath.F90.