pathname-match-p
pathname-match-p Function
Syntax:
pathname-match-p pathname wildcard → generalized-boolean
Arguments and Values:
pathname—a pathname designator .
wildcard—a designator for a wild pathname.
generalized-boolean—a generalized boolean.
Description:
pathname-match-p returns true if pathname matches wildcard, otherwise nil. The matching rules are implementation-defined but should be consistent with directory. Missing components of wildcard default to :wild.
It is valid for pathname to be a wild pathname; a wildcard field in pathname only matches a wildcard field in wildcard (i.e., pathname-match-p is not commutative). It is valid for wildcard to be a non-wild pathname.
Exceptional Situations:
If pathname or wildcard is not a pathname, string, or stream associated with a file an error of type type-error is signaled.
See Also:
directory, pathname, logical-pathname, Section 20.1 (File System Concepts), Section 19.1.2 (Pathnames as Filenames)
translate-logical-pathnameExpanded Reference: pathname-match-p
Basic wildcard matching
pathname-match-p tests whether a pathname matches a wildcard pathname pattern. It returns true if the pathname matches.
(pathname-match-p #P"/tmp/test.lisp"
(make-pathname :directory '(:absolute "tmp")
:name :wild
:type "lisp"))
=> T
Matching with :wild name
The :wild component in a pattern matches any single name.
(pathname-match-p (make-pathname :name "foo" :type "lisp")
(make-pathname :name :wild :type "lisp"))
=> T
(pathname-match-p (make-pathname :name "foo" :type "txt")
(make-pathname :name :wild :type "lisp"))
=> NIL
Matching with :wild-inferiors
The :wild-inferiors directory component matches any number of directory levels.
(pathname-match-p
(make-pathname :directory '(:absolute "home" "user" "src")
:name "main" :type "lisp")
(make-pathname :directory '(:absolute :wild-inferiors)
:name :wild :type "lisp"))
=> T
Non-matching pathnames
When the pathname does not match the pattern, nil is returned.
(pathname-match-p (make-pathname :name "data" :type "csv")
(make-pathname :name "data" :type "txt"))
=> NIL