ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
glob.m File Reference

Go to the source code of this file.

Functions

function glob (in pattern, in anycase)
 Find all files and directory names matching the input pattern by expanding wildcards.
More...
 
function glob2regexp (in glob_str)
 
function ls_regexp (in regexp_fhandle, in path, in varargin)
 
function ls_regexp_tree (in regexp_fhandle, in path, in varargin)
 
function dir_recur (in startdir, in keep_hidden)
 

Function Documentation

◆ dir_recur()

function dir_recur ( in  startdir,
in  keep_hidden 
)

◆ glob()

function glob ( in  pattern,
in  anycase 
)

Find all files and directory names matching the input pattern by expanding wildcards.

This function performs pattern matching of file and directory names, based on wildcard characters.
This function is similar to wildcard expansion performed by the Unix shell and Python glob.glob function, but it can handle by the Unix shell and Python glob.glob function, but it can handle more types of wildcards.
The following list highlights the key differences between this function and the MATLAB intrinsic dir().

  1. glob() supports wildcards for directories.
  2. glob() returns the directory part of pattern.
  3. glob() returns a cell array of matching names.
  4. glob() does not return hidden files and directories that start with '.' unless explicitly specified in pattern.
  5. glob() does not return '.' and '..' unless explicitly specified in pattern.
  6. glob() adds a trailing file separator to directory names.
  7. glob() does not return the contents of a directory when a directory is specified.
    To return contents of a directory, add a trailing '/*'.
  8. glob() returns only directory names when a trailing file separator is specified.
  9. On Windows, glob() is not case sensitive, but it returns matching names exactly in the case as they are defined on the filesystem.
    Case of host and sharename of a UNC path and case of drive letters will be returned as specified in pattern.
Parameters
[in]pattern: The input scalar MATLAB string, containing the search pattern.
Wildcards may be used for basenames and for the directory parts.
If pattern contains directory parts, then these will be included in the output pathList.
Following wildcards can be used:
  1. * match zero or more characters.
  2. ? match any single character.
  3. [ab12] match one of the specified characters.
  4. [^ab12] match none of the specified characters
  5. [a-z] match one character in range of characters
  6. {a,b,c} matches any one of strings a, b or c
  7. All above wildcards do not match a file separator.
  8. ** match zero or more characters including file separators.
    This can be used to match zero or more directory parts and will recursively list matching names.
    Beware that symbolic linked directories or junctions may cause an infinite loop when using the **.
[in]anycase: The input scalar MATLAB logical.
If true, the search will be case-sensitive.
If false, the search will be case-insensitive.
On Windows, anycase is always reset to true even if user-specified.
(optional. default = false on Unix and true on Windows.)
Returns
pathList : The output MATLAB cell array of strings containing the files or directories that match the path specified by string pattern.
isdirList : The output MATLAB cell array of the same size as pathList, each element of which is a MATLAB logical value that is true if and only if the corresponding element of pathList is a directory.


Possible calling interfaces

[pathList, isdirList] = pm.sys.path.glob(pattern)
[pathList, isdirList] = pm.sys.path.glob(pattern, anycase)


Example usage

pm.sys.path.glob("*.m") % list all .m files in current directory.
pm.sys.path.glob("baz/*") % list all files and directories in subdirectory "baz".
* pm.sys.path.glob("b*/*.m") % list all .m files in subdirectory names starting with "b".
% The list will include the names of the matching subdirectories.
pm.sys.path.glob("?z*.m") % list all .m files where the second character is 'z'.
pm.sys.path.glob("baz.[ch]") % matches baz.c and baz.h
pm.sys.path.glob("test.[^ch]") % matches test.a but not test.c or test.h
pm.sys.path.glob("demo.[a-c]") % matches demo.a, demo.b, and demo.c
pm.sys.path.glob("test.{foo,bar,baz}") % matches test.foo, test.bar, and test.baz
pm.sys.path.glob(".*") % list all hidden files in current directory, excluding '.' and '..'
pm.sys.path.glob("*/") % list all subdirectories.
pm.sys.path.glob("**") % recursively list all files and directories,
% starting in current directory (current directory name,
% hidden files and hidden directories are excluded).
pm.sys.path.glob("**.m") % list all m-files anywhere in directory tree,
% including m-files in current directory. This
% is equivalent with '**/*.m'.
pm.sys.path.glob("foo/**/") % recursively list all directories, starting in directory 'foo'.
pm.sys.path.glob("**/.svn/") % list all .svn directories in directory tree.
pm.sys.path.glob("**/.*/**") % recursively list all files in hidden directories only.
[paths, isdir] = pm.sys.path.glob('**'); paths(~isdir) % get all files in directory tree.
function name(in vendor)
Return the MPI library name as used in naming the ParaMonte MATLAB shared library directories.
function list()
Return a list of MATLAB strings containing the names of OS platforms supported by the ParaMonte MATLA...
excluded
Definition: show.m:173


Example usage

1cd(fileparts(mfilename('fullpath'))); % Change working directory to source code directory.
2addpath('../../../../'); % Add the ParaMonte library root directory to the search path.
3
4pm.matlab.show()
5pm.matlab.show('pm.sys.path.glob("*.m")')
6pm.matlab.show( pm.sys.path.glob("*.m") )
7
8pm.matlab.show()
9pm.matlab.show('pm.sys.path.glob("example/array/**")')
10pm.matlab.show( pm.sys.path.glob("example/array/**") )
11
12pm.matlab.show()
13pm.matlab.show('pm.sys.path.glob("example/array/**.m")')
14pm.matlab.show( pm.sys.path.glob("example/array/**.m") )
15
16pm.matlab.show()
17pm.matlab.show('pm.sys.path.glob("example/array/*.m")')
18pm.matlab.show( pm.sys.path.glob("example/array/*.m") )
19
20pm.matlab.show()
21pm.matlab.show('pm.sys.path.glob(".*")')
22pm.matlab.show( pm.sys.path.glob(".*") )
23
24pm.matlab.show()
25pm.matlab.show('[paths, isdir] = pm.sys.path.glob("**"); paths(~isdir) % get all files in directory tree.')
26 [paths, isdir] = pm.sys.path.glob("**"); paths(~isdir) % get all files in directory tree.
function root()
Return a scalar MATLAB string containing the root directory of the ParaMonte library package.

Example output
1
2pm.sys.path.glob("*.m")
3 "main.m"
4 "main.out.m"
5
6pm.sys.path.glob("example/array/**")
7
8pm.sys.path.glob("example/array/**.m")
9
10pm.sys.path.glob("example/array/*.m")
11
12pm.sys.path.glob(".*")
13
14[paths, isdir] = pm.sys.path.glob("**"); paths(~isdir) % get all files in directory tree.
15ans =
16 2x1 string array
17 "main.m"
18 "main.out.m"


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.

Copyright (c) 2013, Peter van den Biggelaar All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution

This software is provided by the copyright holders and contributors "as is" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. in no event shall the copyright owner or contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.

Author:
Joshua Alexander Osborne, May 21 2024, 5:24 AM, University of Texas at Arlington
Fatemeh Bagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.
Amir Shahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin

◆ glob2regexp()

function glob2regexp ( in  glob_str)

◆ ls_regexp()

function ls_regexp ( in  regexp_fhandle,
in  path,
in  varargin 
)

◆ ls_regexp_tree()

function ls_regexp_tree ( in  regexp_fhandle,
in  path,
in  varargin 
)