Generate and return .true.
if the requested move action failed, otherwise return .false.
indicating success.
The procedures of this generic interface perform the move action depending on the type of the two input paths:
- If
from
is an existing file, then,
- If
to
is an existing directory, the source file from
will be moved (with the same old file base name) into the existing destination folder.
- If
to
is an existing file, then the source file will overwrite the existing destination file if and only if the optional argument forced = .true.
is specified.
- If
to
is a non-existing path, then to
is interpreted as a non-existing destination file. If so,
- The (potentially nested non-existing) dirname of the destination file will be created.
- The source file
from
will be moved to the destination folder with a new name that is the base name of to
.
- If
from
is an existing directory, then,
- If
to
is an existing directory, the contents of the source directory from
will be moved into the existing destination folder.
- Existing files with the same name as in the source folder
from
will be overwritten only if the optional argument forced = .true.
is specified.
- If
to
is an existing file, the program will not perform the requested move action and will return failed = .true.
.
- If
to
is a non-existing path, then to
is interpreted as a non-existing destination directory.
- Firstly, the (potentially nested) non-existing directory will be generated.
- Secondly, the contents of the source directory
from
will be moved into the newly-created destination directory to
.
- If
from
is neither an existing file nor an existing folder, the program will not perform the requested move action and will return failed = .true.
.
This procedure is capable of moving a file or a directory to nonexistent (potentially nested) directories.
The move request is done 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.
- On POSIX-compliant shells, the commands
mv -arn
and mv -arf
are used to perform the move regularly or forcefully (with overwriting), respectively.
- On Windows-based terminals, the commands
xmove /e /q /s
and xmove /e /q /s /Y
are used to perform the move regularly or forcefully (with overwriting), respectively.
- Parameters
-
[in] | from | : The input scalar character of default kind SK containing a POSIX-style or Windows-style path to a file or directory.
|
[in] | to | : The input scalar character of default kind SK containing a POSIX-style or Windows-style path to which the path from should be moved.
When the input argument from points to a single file, there is ambiguity about how the destination path should be interpreted.
As such, if to points to a (potentially non-existing) folder, make sure to end it with a suitable directory separator getDirSep before passing it to the procedures under this generic integer.
Otherwise, to is assumed to point to a file name.
|
[in] | forced | : The input scalar logical of default kind LK. If .true. the move action will overwrite the destination to if it already exists.
This input argument is relevant only if the input destination path partially or entirely contains the same files in from .
(optional, default = .false. ) |
[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 shell action to terminate before returning the control to the Fortran program.
-
Otherwise, the system call will be done asynchronously and the success of the action will not be verified.
(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 performing the requested task.
This includes the possibility of the input path from
not existing before the move action or the destination path to
not existing after the move action.
Possible calling interfaces ⛓
character(2047, SK) :: errmsg
logical(LK) :: failed, forced
logical(LK) :: wait
integer(IK) :: ntry
failed
= isFailedMove(from, to, forced
= forced,
wait = wait, ntry
= ntry,
errmsg = errmsg)
Generate and return .true. if the requested move action failed, otherwise return ....
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(....
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...
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 paths 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.
-
This procedure interprets the input paths verbatim.
This procedure potentially calls the operating system to create the input destination path directories.
To minimize security vulnerabilities and to properly handle the presence of whitespace or other potentially problematic characters, the input path will be interpreted verbatim by calling getPathVerbatim.
-
Asynchronous move action.
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.
-
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
- isFailedCopy
isFailedMove
isFailedRemove
isFailedMakeDir
Example usage ⛓
9 character(:, SK),
allocatable :: from, to
11 type(display_type) :: disp
15 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
16 call disp%show(
"! Move file to a new non-existing destination file.")
17 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
21 call disp%show(
"from = SK_'main.F90' ! define the source path name.")
23 call disp%show(
"to = getPathNew(ext = SK_'.main.F90') ! define a random unique path name.")
26 call disp%show( to , deliml
= SK_
"""" )
27 call disp%show(
"[isFile(from), isFile(to)]")
29 call disp%show(
"if (isFailedMove(from, to)) error stop 'movement failed.'")
30 if (
isFailedMove(from, to))
error stop 'movement failed.'
31 call disp%show(
"[isFile(from), isFile(to)]")
33 call disp%show(
"if (isFailedMove(to, from)) error stop 'movement failed.'")
34 if (
isFailedMove(to, from))
error stop 'movement failed.'
35 call disp%show(
"[isFile(from), isFile(to)]")
40 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
41 call disp%show(
"! Move file to a new non-existing doubly-nested destination folder.")
42 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
46 call disp%show(
"from = SK_'main.F90' ! define the source path name.")
48 call disp%show(
"to = getPathNew(dir = getPathNew(), prefix = SK_'sub')//getDirSep() ! Ending the directory name with directory separator is crucial if it does not exit already, otherwise it is interpreted as file name.")
51 call disp%show( to , deliml
= SK_
"""" )
52 call disp%show(
"[isDir(from), isFile(from), isDir(to), isFile(to)]")
54 call disp%show(
"if (isFailedMove(from, to)) error stop 'movement failed.'")
55 if (
isFailedMove(from, to))
error stop 'movement failed.'
56 call disp%show(
"[isFile(from), isFile(to//getDirSep()//from)]")
58 call disp%show(
"if (isFailedMove(to//from, from)) error stop 'movement failed.'")
59 if (
isFailedMove(to
//from, from))
error stop 'movement failed.'
60 call disp%show(
"[isFile(from), isFile(to)]")
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 ....
Generate and return .true. is the input path is a file (not a 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.
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 ⛓
10"new_20241027_224347_969_pid_1.main.F90"
29"new_20241027_224347_976_pid_1/sub20241027_224347_978_pid_1/"
35if (
isFailedMove(to
//from, from))
error stop 'movement failed.'
- Test:
- test_pm_sysPath
- Todo:
- High Priority: The current Fortran standard 202x does not allow passing characters of non-default kind to the intrinsic Fortran statements and procedures.
As such, the implementation of this procedure for non-default character
kinds leads to compile-time kind mismatch errors.
This procedure should be converted back to a generic interface in the future when non-default character kinds are also fully supported by the intrinsic functions.
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 3626 of file pm_sysPath.F90.