panda3d.core.GlobPattern

class GlobPattern

This class can be used to test for string matches against standard Unix- shell filename globbing conventions. It serves as a portable standin for the Posix fnmatch() call.

A GlobPattern is given a pattern string, which can contain operators like *, ?, and []. Then it can be tested against any number of candidate strings; for each candidate, it will indicate whether the string matches the pattern or not. It can be used, for example, to scan a directory for all files matching a particular pattern.

Inheritance diagram

Inheritance diagram of GlobPattern

__init__(copy: GlobPattern) → None
__init__(pattern: str) → None
assign(copy: GlobPattern) → GlobPattern
Return type

GlobPattern

setPattern(pattern: str) → None

Changes the pattern string that the GlobPattern object matches.

getPattern() → str

Returns the pattern string that the GlobPattern object matches.

setCaseSensitive(case_sensitive: bool) → None

Sets whether the match is case sensitive (true) or case insensitive (false). The default is case sensitive.

getCaseSensitive() → bool

Returns whether the match is case sensitive (true) or case insensitive (false). The default is case sensitive.

setNomatchChars(nomatch_chars: str) → None

Specifies a set of characters that are not matched by * or ?.

getNomatchChars() → str

Returns the set of characters that are not matched by * or ?.

matches(candidate: str) → bool

Returns true if the candidate string matches the pattern, false otherwise.

matchesFile(candidate: Filename) → bool

Treats the GlobPattern as a filename pattern, and returns true if the given filename matches the pattern. Unlike matches(), this will not match slash characters for single asterisk characters, and it will ignore path components that only contain a dot.

output(out: ostream) → None
hasGlobCharacters() → bool

Returns true if the pattern includes any special globbing characters, or false if it is just a literal string.

getConstPrefix() → str

Returns the initial part of the pattern before the first glob character. Since many glob patterns begin with a sequence of static characters and end with one or more glob characters, this can be used to optimized searches through sorted indices.

matchFiles(cwd: Filename) → object
matchFiles(results: vector_string, cwd: Filename) → int

Treats the GlobPattern as a filename pattern, and returns a list of any actual files that match the pattern. This is the behavior of the standard Posix glob() function. Any part of the filename may contain glob characters, including intermediate directory names.

If cwd is specified, it is the directory that relative filenames are taken to be relative to; otherwise, the actual current working directory is assumed.

The return value is the number of files matched, which are added to the results vector.

property pattern
Getter

Returns the pattern string that the GlobPattern object matches.

Setter

Changes the pattern string that the GlobPattern object matches.

Return type

string

property case_sensitive
Getter

Returns whether the match is case sensitive (true) or case insensitive (false). The default is case sensitive.

Setter

Sets whether the match is case sensitive (true) or case insensitive (false). The default is case sensitive.

Return type

bool

property nomatch_chars
Getter

Returns the set of characters that are not matched by * or ?.

Setter

Specifies a set of characters that are not matched by * or ?.

Return type

string