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

Generate and return .true. if the attempt to fetch the directory listing of the specified input path fails, otherwise, return .false..
More...

Detailed Description

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,

  1. a vector of scalar string containers css_type.
  2. 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,
  1. 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.
  2. 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,
  1. pathCount represents the number of paths in the output list, and
  2. index(1,:) is the vector of positions of the starting character of individual paths in list, and
  3. 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,
  1. sort = "name": Sort all items alphabetically by their names.
  2. sort = "tmod": Sort all items chronologically by their dates of last modification (oldest first).
  3. sort = "tacc": Sort all items chronologically by their dates of last access (oldest first).
  4. sort = "size": Sort all items by their size (smallest first).
  5. 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

use pm_kind, only: SK, IK, LK
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) ! `list` is a vector of string containers.
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...
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
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
This module contains classes and procedures for manipulating system file/folder paths.
Definition: pm_sysPath.F90:274
Remarks
The procedures under discussion are impure.
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

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 :: list
10 integer(IK) , allocatable :: index(:,:)
11 integer :: i
12
13 type(display_type) :: disp
14 disp = display_type(file = "main.out.F90")
15
16 call disp%skip()
17 call disp%show("isFailedMakeDir('./temp')")
18 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
21 call disp%skip()
22
23 call disp%skip()
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
26 call disp%skip()
27
28end 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 .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...
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
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
2isFailedMakeDir('./temp')
3F
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
5"CMakeFiles/"
6"temp/"
7"CMakeCache.txt"
8"CMakeLists.txt"
9"Makefile"
10"build.sh"
11"cmake_install.cmake"
12"main.F90"
13"main.exe"
14"main.out.F90"
15
16
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
18"getBaseName/"
19"getDirCurrent/"
20"getDirHome/"
21"getDirName/"
22"getDirSep/"
23"getDirSeps/"
24"getExtName/"
25"getFileName/"
26"getIndexBaseName/"
27"getIndexDirName/"
28"getIndexExtName/"
29"getPathAbs/"
30"getPathExpandedUser/"
31"getPathHostNameIndex/"
32"getPathJoined/"
33"getPathMatch/"
34"getPathNew/"
35"getPathPosix/"
36"getPathPosixEscaped/"
37"getPathQuoted/"
38"getPathSep/"
39"getPathTemp/"
40"getPathVerbatim/"
41"getPathVerbatimCMD/"
42"getPathVerbatimFish/"
43"getPathVerbatimPosix/"
44"getPathVerbatimPowerShell/"
45"getPathWindows/"
46"glob/"
47"hasDriveLetter/"
48"isDir/"
49"isExtant/"
50"isFailedChangeDir/"
51"isFailedCopy/"
52"isFailedGlob/"
53"isFailedList/"
54"isFailedMakeDir/"
55"isFailedMakeDirTemp/"
56"isFailedMove/"
57"isFailedRemove/"
58"isFile/"
59"isPathAbsPosix/"
60"isPathAbsWindows/"
61"ls/"
62"setPathMatch/"
63"setPathPosix/"
64"setPathPosixEscaped/"
65"setPathWindows/"
66
67
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.

  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, 7:03 AM, Institute for Computational Engineering and Sciences (ICES), The University of Texas Austin

Definition at line 1257 of file pm_sysPath.F90.


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