Howto Path Tools

Expand a Wildcard Path

The interface

1
filesysobjects.pathtools.expandpath(*paths, **kargs)

Provides the normalization of path lists which may contain regexpr, globs, and environment variables. This also splits contained multiple-path entries into each combined path.

The following call expands to all wildcards:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
arg = tdata + '/b/*/c.sh'
#
# some interpretations:
#
#   GLOB:'/b/*/c.sh' => as RE: '/b/.+/c.sh'
#   RE:'/b/*/c.sh' some equivalents subsets: '/b////c.sh','/b/c.sh', '/bc.sh'
#
res = filesysobjects.pathtools.expandpath(arg, wildcards=W_RE)

res = filesysobjects.pathtools.expandpath(arg, wildcards=W_GLOB)

The similar call with platform independent normalization bt defining a tpf - target platform format, here posix.

1
2
3
4
arg = tdata + '/b/*/c.sh'
arg = filesysobjects.apppaths.normapppathx(arg, tpf='posix')

res = filesysobjects.pathtools.expandpath(arg, wildcards=W_RE, tpf='posix')

See [API] / [code]

Find with ‘re’ and ‘glob’ Pattern

The interface findpattern supports a large set of options, which more comprising in some parts than the find utility of POSIX. The missing features are closing step by step. This includes the library as well as the command line interface.

The following call finds all filesystem entries in the current directory:

1
filesysobjects.pathtools.findpattern(level=0)

The following call searches by wildcards the subdirectories of tdata.

1
2
3
4
5
6
7
tdata = /my/search/start
search_path_expr = tdata+os.path.normpath("/'''[^/]'''+/.*/[c]+.sh")

filesysobjects.pathtools.findpattern(
   tdata,
   wildcards=search_path_expr
   )

See [API] / [code]

Find Relative Sub-Paths in Search Paths

The interface findrelpath_in_searchpath supports the search of relative subpaths to each entry within a list of search paths.

The following call finds all filesystem entries within a specific subpath:

1
2
3
4
5
filesysobjects.pathtools.findrelpath_in_searchpath(
   rpath,         # relative path
   plist,         # path list to be searched
   subsplit=True  # sets split of contained search path-strings
   )

See [API] / [code]