Is it possible to 'stat' a file and find its file type - regular or directory?
Read the chapter about a portable pathname library from Peter Seibel's Practical Common Lisp book. It's available for free. It has a function file-exists-p that will return a pathname when the file exists or nil if it doesn't. The returned pathname will be in directory form if it's a directory. He also gives another function for checking if the pathname is indeed in directory form.
BTW the whole book is really worth reading so check it out if you haven't already.
CL-FAD has a function DIRECTORY-EXISTS-P which, when used in combination with PATHNAME-AS-DIRECTORY canonicalizes the pathname (prevents failure when handed a string like "/path/dir-without-trailing-slash") and achives what you're asking for.
(CL-FAD:DIRECTORY-PATHNAME-P (CL-FAD:PATHNAME-AS-DIRECTORY (PROBE-FILE "/path/missing-slash")))
I think there are several ways. probe-file
followed by checking the returned true name to determine that it has a directory name but not a filename and type should do it. e.g. for a directory
(pathname-name (probe-file filespec))
-> NIL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With