Generate and return .true.
if the attempt to fetch the directory listing of the specified input path
fails, otherwise, return .false.
.
This generic interface partially replicates the common behaviors in the dir
command of Windows terminals and the ls
command of POSIX-compliant shells.
The returned list
of directory contents can be either,
-
a vector of scalar string containers css_type.
-
a scalar string container, containing the all directory contents concatenated within a single string whose records start and stop elements are returned in the output array
index(1:2,:)
.
This format is particularly efficient as it involved only one allocation compared to the former containerized storage mode.
- Parameters
-
[in] | path | : The input scalar character of default kind SK of arbitrary length type parameter containing the directory or file to list.
Note that the input path is interpreted verbatim.
See isFailedGlob for pattern matching (globing), the results of which can be passed as input to this generic interface.
|
[out] | list | : The output object that can be either,
-
an
allocatable scalar character of default kind SK containing the path entries in sequence, such that the next path entry starts immediately after the last character of the previous entry.
-
an
allocatable vector of containers of type css_type containing scalar strings of kind SK, each element of which contains the path to one entry in the directory listing.
Note that the allocation status or the contents of list remain undefined if failed = .true. on return. |
[out] | index | : The output allocatable array of type integer of default kind IK of shape `(1:2,1:pathCount) where,
-
pathCount represents the number of paths in the output list, and
-
index(1,:) is the vector of positions of the starting character of individual paths in list , and
-
index(2,:) is the vector of positions of the ending character of individual paths in list .
By definition, index(1,1) = 1 and index(2,pathCount) = len(list) .
such that the next path entry starts immediately after the last character of the previous entry.
Note that the allocation status or the contents of index remain undefined if failed = .true. on return.
(optional. It must be present if and only if the input argument list is a scalar character of default kind SK.) |
[in] | sort | : The input scalar character of default kind SK of arbitrary length type parameter containing the sorting methodology used for sorting paths in the listing.
The following values are supported,
-
sort = "name" : Sort all items alphabetically by their names.
-
sort = "tmod" : Sort all items chronologically by their dates of last modification (oldest first).
-
sort = "tacc" : Sort all items chronologically by their dates of last access (oldest first).
-
sort = "size" : Sort all items by their size (smallest first).
-
sort = "fext" : Sort all items alphabetically by their file name extension (empty extensions first).
(optional, default = "name" ) |
[in] | showdir | : The input scalar logical of default kind LK. If .true. , the subdirectories (if any exist) in the specified path will be also listed.
(optional, default = .true. ) |
[in] | showfile | : The input scalar logical of default kind LK. If .true. , the file (if any exist) in the specified path will be also listed.
(optional, default = .true. ) |
[in] | showhidden | : The input scalar logical of default kind LK. If .true. , the hidden files (if any exist) in the specified path will be also listed.
(optional, default = .true. ) |
[in] | reversed | : The input scalar logical of default kind LK. If .true. , the sorting of the list will be reversed.
(optional, default = .false. ) |
[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.
A length of LEN_IOMSG characters is likely sufficient to capture most error messages in full.
(optional. Its presence is relevant only if failed is also present.) |
- Returns
failed
: The output scalar logical
of default kind LK.
It is .true.
if and only if an error occurs while resolving path
.
Possible calling interfaces ⛓
character(:, SK), allocatable :: string
type(css_type), allocatable :: list(:)
integer(IK), allocatable :: index(:,:)
logical(LK) :: failed
logical(LK) :: showdir
logical(LK) :: showfile
logical(LK) :: showhidden
failed
= isFailedList(path, list(:), sort
= sort, showdir
= showdir, showfile
= showfile, showhidden
= showhidden, reversed
= reversed,
errmsg = errmsg)
failed
= isFailedList(path, string, index, sort
= sort, showdir
= showdir, showfile
= showfile, showhidden
= showhidden, reversed
= reversed,
errmsg = errmsg) ! `string` is a scalar string.
Generate and return .true. if the attempt to fetch the directory listing of the specified input path ...
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.
- Note
- The interface returning
list
as a scalar string of concatenated paths is significantly faster than a container implementation by reducing the number of allocations from an arbitrarily large number to < 3
, frequently only 1
.
The runtime performance gain is particularly significant when the returned list contains thousands of paths.
-
The procedures of this generic interface can handle characters of any kind (including nongraphical ASCII characters like newline) on Unix systems.
- See also
- ls
isFailedList
Example usage ⛓
9 character(:, SK),
allocatable :: list
10 integer(IK) ,
allocatable ::
index(:,:)
13 type(display_type) :: disp
17 call disp%show(
"isFailedMakeDir('./temp')")
19 call disp%show(
"if (isFailedList('.', list, index)) then; error stop; else; do i = 1, size(index,2); call disp%show(list(index(1,i):index(2,i)), deliml = SK_'""'); end do; end if")
20 if (
isFailedList(
'.', list, index))
then;
error stop;
else;
do i
= 1,
size(index,
2);
call disp%show(list(
index(
1,i):
index(
2,i)), deliml
= SK_
"""");
end do;
end if
24 call disp%show(
"if (isFailedList('..', list, index)) then; error stop; else; do i = 1, size(index,2); call disp%show(list(index(1,i):index(2,i)), deliml = SK_'""'); end do; end if")
25 if (
isFailedList(
'..', list, index))
then;
error stop;
else;
do i
= 1,
size(index,
2);
call disp%show(list(
index(
1,i):
index(
2,i)), deliml
= SK_
"""");
end do;
end if
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 .true. if the attempt to create the requested directory path fails,...
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 ⛓
4if (
isFailedList(
'.', list, index))
then;
error stop;
else;
do i
= 1,
size(index,
2);
call disp%show(list(
index(
1,i):
index(
2,i)), deliml
= SK_
'"');
end do;
end if
17if (
isFailedList(
'..', list, index))
then;
error stop;
else;
do i
= 1,
size(index,
2);
call disp%show(list(
index(
1,i):
index(
2,i)), deliml
= SK_
'"');
end do;
end if
31"getPathHostNameIndex/"
43"getPathVerbatimPosix/"
44"getPathVerbatimPowerShell/"
- 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 the procedures of this generic interface 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.
- Todo:
- Critical Priority: Support for Windows powershell must be added.
- Todo:
- Critical Priority: Support for input wildcard patterns must be added with the help of isFailedGlob.
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, 7:03 AM, Institute for Computational Engineering and Sciences (ICES), The University of Texas Austin
Definition at line 1257 of file pm_sysPath.F90.