file-error-pathname
file-error-pathname Function
Syntax:
file-error-pathname condition → pathspec
Arguments and Values:
condition—a condition of type file-error.
pathspec—a pathname designator .
Description:
Returns the “offending pathname” of a condition of type file-error.
Exceptional Situations:
See Also:
file-error, Chapter 9 (Conditions)
Expanded Reference: file-error-pathname
Retrieving the offending pathname
file-error-pathname extracts the pathname associated with a file-error condition, identifying which file caused the error.
(handler-case
(open "/tmp/nonexistent-dir-xyz/test.txt")
(file-error (c)
(file-error-pathname c)))
=> #P"/tmp/nonexistent-dir-xyz/test.txt"
Using with handler-bind for logging
You can use file-error-pathname within a handler to log or report which file caused a problem.
(handler-case
(delete-file "/tmp/absolutely-no-such-file-xyz.txt")
(file-error (c)
(format nil "Cannot operate on: ~A"
(namestring (file-error-pathname c)))))
=> "Cannot operate on: /tmp/absolutely-no-such-file-xyz.txt"
Works with programmatically created conditions
The function also works on conditions created with make-condition.
(let ((c (make-condition 'file-error
:pathname "/missing/file.txt")))
(file-error-pathname c))
=> "/missing/file.txt"