I tried:
(mapcar (lambda(x)(princ x)(princ #\newline)) (directory pathname))
(Sorry if I'm off hard to write code in my email client ).
This lists all files in a directory, but fails to list the
subdirectories.
Also how can I get various properties of the file ( size, ctime,
atime...).
In article <···················@nntp.interaccess.com>,
Thaddeus L Olczyk <······@interaccess.com> wrote:
>I tried:
>
>(mapcar (lambda(x)(princ x)(princ #\newline)) (directory pathname))
>(Sorry if I'm off hard to write code in my email client ).
>
>This lists all files in a directory, but fails to list the
>subdirectories.
You have to write a recursive function that descends into subdirectories.
Unfortunately, there's no portable way to determine which names are
subdirectories.
>Also how can I get various properties of the file ( size, ctime,
>atime...).
There are no standard Common Lisp functions to get that OS-specific
information, you have to use implementation-dependent functions.
--
Barry Margolin, ······@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
On Thu, 27 Dec 2001 21:06:23 GMT, Barry Margolin <······@genuity.net>
wrote:
>>This lists all files in a directory, but fails to list the
>>subdirectories.
>
>You have to write a recursive function that descends into subdirectories.
>Unfortunately, there's no portable way to determine which names are
>subdirectories.
I was hoping probe-file would do the job.
But the point is moot. directory does not return the subdirs only the
files.
······@interaccess.com (Thaddeus L Olczyk) writes:
> On Thu, 27 Dec 2001 21:06:23 GMT, Barry Margolin <······@genuity.net>
> wrote:
>
> >>This lists all files in a directory, but fails to list the
> >>subdirectories.
> >
> >You have to write a recursive function that descends into subdirectories.
> >Unfortunately, there's no portable way to determine which names are
> >subdirectories.
>
> I was hoping probe-file would do the job.
> But the point is moot. directory does not return the subdirs only the
> files.
That's implementation-dependent. CMUCL, for example, will do:
* (directory "/home/tfb/tmp/")
(#p"/home/tfb/tmp/bar" #p"/home/tfb/tmp/baz" #p"/home/tfb/tmp/foo/")
* (directory "/home/tfb/tmp/" :check-for-subdirs nil)
(#p"/home/tfb/tmp/bar" #p"/home/tfb/tmp/baz" #p"/home/tfb/tmp/foo")
--
/|_ .-----------------------.
,' .\ / | No to Imperialist war |
,--' _,' | Wage class war! |
/ / `-----------------------'
( -. |
| ) |
(`-. '--.)
`. )----'
I don't know of a portable way but on in ACL/Windows the following will
return directories
(remove-if-not #'file-directory-p
(directory "c:\\*"))
Use remove-if for pure files
Karsten
"Thaddeus L Olczyk" <······@interaccess.com> wrote in message
························@nntp.interaccess.com...
> On Thu, 27 Dec 2001 21:06:23 GMT, Barry Margolin <······@genuity.net>
> wrote:
>
> >>This lists all files in a directory, but fails to list the
> >>subdirectories.
> >
> >You have to write a recursive function that descends into subdirectories.
> >Unfortunately, there's no portable way to determine which names are
> >subdirectories.
>
> I was hoping probe-file would do the job.
> But the point is moot. directory does not return the subdirs only the
> files.
Thaddeus L Olczyk wrote:
>
> On Thu, 27 Dec 2001 21:06:23 GMT, Barry Margolin <······@genuity.net>
> wrote:
>
> >>This lists all files in a directory, but fails to list the
> >>subdirectories.
> >
> >You have to write a recursive function that descends into subdirectories.
> >Unfortunately, there's no portable way to determine which names are
> >subdirectories.
That sounds familiar. ;)
> I was hoping probe-file would do the job.
> But the point is moot. directory does not return the subdirs only the
> files.
That's not true (for lispworks, anyway). My code (with some extras I
wanted):
;;; return a list of all files under root, which can be a string or
pathname.
;;; If you include extra args like "h" "m" "rtf" "rtfd" "c" or whatever,
;;; only files with those extensions will be collected.
;;; (build-tree ".") =>
;;; (#P"/usr/home/ericmoss/projects/autodoc/autodoc.lisp"
;;; #P"/usr/home/ericmoss/projects/autodoc/autodoc.py"
;;; #P"/usr/home/ericmoss/projects/autodoc/test/foo.h"
;;; #P"/usr/home/ericmoss/projects/autodoc/test/foo.m"
;;; ...)
(defun collect-files (root &rest filetypes)
(let ((result (list)))
(labels ((build-it (inode)
(cond
((file-directory-p inode)
(dolist (leaf (directory (namestring inode)))
(build-it leaf)))
(t
(if (or (null filetypes)
(member (pathname-type inode) filetypes
:test #'equal))
(pushnew inode result))))))
(build-it (truename root)))
result))
Barry Margolin <······@genuity.net> writes:
> In article <···················@nntp.interaccess.com>,
> Thaddeus L Olczyk <······@interaccess.com> wrote:
> >I tried:
> >(mapcar (lambda(x)(princ x)(princ #\newline)) (directory pathname))
> >(Sorry if I'm off hard to write code in my email client ).
> >This lists all files in a directory, but fails to list the
> >subdirectories.
> You have to write a recursive function that descends into
> subdirectories. Unfortunately, there's no portable way to determine
> which names are subdirectories.
> >Also how can I get various properties of the file ( size, ctime,
> >atime...).
> There are no standard Common Lisp functions to get that OS-specific
> information, you have to use implementation-dependent functions.
Obviously this can't come as a part of the overall CL standards, as
there _are_ other platforms than Unix.
On the other hand, having directories as special files has gotten
pretty pervasive, and it's _really_ irritating when DIRECTORY treats
directories rather differently between imps.
It is rather unfortunate that a set of "conventions" have not arisen
in this regard, that works across implementations that run on
Unix-like platforms.
--
(concatenate 'string "cbbrowne" ·@acm.org")
http://www.ntlug.org/~cbbrowne/spiritual.html
Rules of the Evil Overlord #8. "After I kidnap the beautiful princess,
we will be married immediately in a quiet civil ceremony, not a lavish
spectacle in three weeks' time during which the final phase of my plan
will be carried out." <http://www.eviloverlord.com/>
On Fri, 28 Dec 2001 21:37:37 GMT, ········@acm.org wrote:
>
>> >Also how can I get various properties of the file ( size, ctime,
>> >atime...).
>
>> There are no standard Common Lisp functions to get that OS-specific
>> information, you have to use implementation-dependent functions.
>
>Obviously this can't come as a part of the overall CL standards, as
>there _are_ other platforms than Unix.
>
>On the other hand, having directories as special files has gotten
>pretty pervasive, and it's _really_ irritating when DIRECTORY treats
>directories rather differently between imps.
>
>It is rather unfortunate that a set of "conventions" have not arisen
>in this regard, that works across implementations that run on
>Unix-like platforms.
>--
So what would it take to get the providers of CL on Unix and Windows
systems to agree to a set of conventions in this regard?
And how extensive need these conventions be? Seems like a few simple
statements about exactly what DIRECTORY and PROBE-FILE produce would
go a long way here. Would any other functions need to have specific
conventions defined for Unix and Windows?