File.list
Group: Input
Documentation
Lists files contained in the directory denoted by this file.
The name_filter
can contain the following special characters: - "?"
- which matches a single filename character (so it will not match a "/"
). - "*"
- which matches any number of characters, but again does not cross directories. - "**"
- which matches any number of characters and can cross directories. - "\"
- can be used to escape the characters with special meaning; to get a single backslash, you need to specify it twice; you also need to keep in mind that the interpolating string literal also uses "\"
as an escape sequence, so you need to type '\\\\'
to get a single backslash for the glob pattern, unless you use the raw strings, where you only need to escape once: "\\"
. - Brackets can be used to match exactly one character from some set of characters. For example "[xy]"
matches "x"
or "y"
. Character ranges can also be specified: "[a-z]"
matches any character from "a"
to "z"
. An exclamation mark can be used to negate the match, i.e. "[!xz]"
will match any characters except for "x"
and "z"
. Moreover the ranges and single characters can be used together, so for example "[a-cxy]"
will match "a"
, "b"
, "c"
, "x"
or "y"
. Within the brackets, the special characters "*"
, "?"
and "\"
stand for themselves instead of their special meanings. - Braces allow to specify multiple patterns (separated with a comma), one of which must be matched. For example: "{abc,x*}"
will match either the name "abc"
or any name starting with "x"
. The groups cannot be nested. If recursive
is set to True and a name_filter
does not contain **
, it will be automatically prefixed with **/
to allow matching files in subdirectories.
Arguments
name_filter
: A glob pattern that can be used to filter the returned files. If it is not specified, all files are returned.recursive
: Specifies whether the returned list of files should include also files from the subdirectories. If set toFalse
(the default), only the immediate children of the listed directory are considered.
Examples
List all files with ".md" or ".txt" extension in the example directory
and any of its subdirectories.
import Standard.Examples
example_list_md_files =
Examples.data_dir.list name_filter="**.{txt,md}" recursive=True