tags:

views:

51

answers:

4

Is it possible to 'stat' a file and find its file type - regular or directory?

A: 

CLISP has a function EXT:PROBE-DIRECTORY, which tells you whether a file exists and is a directory.

Note that this function is specific to CLISP and not standard common list.

sepp2k
Am sorry but is GNU Common Lisp and GNU CLISP the same? I am using GNU Common Lisp (GCL 2.6.6 on Windows) but I could not find the said package "ext".
hyper_w
@hyper: No, GCL and CLISP are two different implementations of the Common Lisp language. Since you tagged this `clisp` I assumed you were using the latter.
sepp2k
Removed the clisp tag. Thanks!
hyper_w
A: 

I don't know if there's a portable built-in way to do it, but CL-FAD has a function DIRECTORY-EXISTS-P which might help.

Ken
It doesn't look like this will work with GCL. At least GCL is not listed under "Supported Lisp implementations"
sepp2k
I guess the good news is that, as GCL has not had a release in over half a decade, if you figure out how to do it there you probably won't have to worry about it changing on you any time soon!
Ken
I checked the source code of CL-FAD - the said function only works for Allegro and LispWorks.
hyper_w
hyper_w: The function only has *special cases* for Allegro and Lispworks. The library claims to support 11 different compilers, and I bet it probably works for more than that.
Ken
+2  A: 

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.

jondro
The CL-FAD library *is* Peter Seibel's chapter, packaged for general use. The DIRECTORY-EXISTS-P function does exactly what you describe.
Ken
I didn't know that. Thanks for the info.
jondro
+1  A: 

There are I think 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

John