From: Andy
Subject: Newbie question: Standard way for accessing files ?
Date: 
Message-ID: <3CCE9063.49BEC8DB@smi.de>
Hi all,
i want to find all files in a given directory (particular all *.lisp
files).
Is there a standard way or package for doing such kind of things or do i
need
to use the OS calls via FFI.

Best regards
AHz

From: Marco Antoniotti
Subject: Re: Newbie question: Standard way for accessing files ?
Date: 
Message-ID: <y6cheltme0z.fsf@octagon.mrl.nyu.edu>
Andy <···@smi.de> writes:

> Hi all,
> i want to find all files in a given directory (particular all *.lisp
> files).
> Is there a standard way or package for doing such kind of things or do i
> need
> to use the OS calls via FFI.

        (directory "*.*")

will get you a list of pathnames (now, what are pathnames?) in the
"default" directory.

Of course the above can also be formulated as

        (directory (make-pathname :name :wild :type :wild))

Of course a perusal of the spec dealing with
`*defalut-pathname-defauls*' will help.

Feeling the Force? :)

Cheers

-- 
Marco Antoniotti ========================================================
NYU Courant Bioinformatics Group        tel. +1 - 212 - 998 3488
719 Broadway 12th Floor                 fax  +1 - 212 - 995 4122
New York, NY 10003, USA                 http://bioinformatics.cat.nyu.edu
                    "Hello New York! We'll do what we can!"
                           Bill Murray in `Ghostbusters'.
From: Kent M Pitman
Subject: Re: Newbie question: Standard way for accessing files ?
Date: 
Message-ID: <sfw7kmp5bhz.fsf@shell01.TheWorld.com>
Marco Antoniotti <·······@cs.nyu.edu> writes:

> Andy <···@smi.de> writes:
> 
> > Hi all,
> > i want to find all files in a given directory (particular all *.lisp
> > files).
> > Is there a standard way or package for doing such kind of things or do i
> > need
> > to use the OS calls via FFI.
> 
>         (directory "*.*")
> 
> will get you a list of pathnames (now, what are pathnames?) in the
> "default" directory.
> 
> Of course the above can also be formulated as
> 
>         (directory (make-pathname :name :wild :type :wild))

This is much more portable than the previous.

Though I would usually go to some trouble to make sure I had an 
appropriately explicit directory.  I hate leaving that to chance.
If you want to rely on the non-portable notion of a working dir,
do so by calling the non-portable function that returns it, so the
reliance is explicit.

It's popular to use *'s as wildcards in namestrings, but it's not required.
Using :wild is more reliable.
 
> Of course a perusal of the spec dealing with
> `*defalut-pathname-defauls*' will help.

   *default-pathname-defaults* 
        ^^                 ^
From: Andy
Subject: Re: Newbie question: Standard way for accessing files ?
Date: 
Message-ID: <3CCEBEB1.4F0627C0@smi.de>
Thanks. Exact what i'm looking for.
Best regards
AHz

Marco Antoniotti wrote:
> 
> Andy <···@smi.de> writes:
> 
> > Hi all,
> > i want to find all files in a given directory (particular all *.lisp
> > files).
> > Is there a standard way or package for doing such kind of things or do i
> > need
> > to use the OS calls via FFI.
> 
>         (directory "*.*")
> 
> will get you a list of pathnames (now, what are pathnames?) in the
> "default" directory.
> 
> Of course the above can also be formulated as
> 
>         (directory (make-pathname :name :wild :type :wild))
> 
> Of course a perusal of the spec dealing with
> `*defalut-pathname-defauls*' will help.
> 
> Feeling the Force? :)
> 
> Cheers
> 
> --
> Marco Antoniotti ========================================================
> NYU Courant Bioinformatics Group        tel. +1 - 212 - 998 3488
> 719 Broadway 12th Floor                 fax  +1 - 212 - 995 4122
> New York, NY 10003, USA                 http://bioinformatics.cat.nyu.edu
>                     "Hello New York! We'll do what we can!"
>                            Bill Murray in `Ghostbusters'.
From: Coby Beck
Subject: Re: Newbie question: Standard way for accessing files ?
Date: 
Message-ID: <bnzz8.456$GG6.6642@news3.calgary.shaw.ca>
Andy <···@smi.de> wrote in message ······················@smi.de...
> Hi all,
> i want to find all files in a given directory (particular all *.lisp
> files).
> Is there a standard way or package for doing such kind of things or do i
> need
> to use the OS calls via FFI.

(let ((*default-pathname-defaults* "C:\\mystuff\\lisp\\"))
   (mapcar #'file-namestring (directory "*.lisp")))

If you want file names, the above does the trick for me using LW on Windows.
If you want the whole path, leave out the file-namestring part.
with-open-file will be happy with the namestring if
*default-pathname-defaults* is bound appropriately.

(warning:  I have only used this kind of thing at the "it seems to be
working" level and don't know much about portable pathnames et al.)

--
Coby Beck
(remove #\Space "coby 101 @ bigpond . com")
From: Nils Goesche
Subject: Re: Newbie question: Standard way for accessing files ?
Date: 
Message-ID: <87u1ptkvja.fsf@darkstar.cartan>
"Coby Beck" <·····@mercury.bc.ca> writes:

> Andy <···@smi.de> wrote in message ······················@smi.de...

> > i want to find all files in a given directory (particular all
> > *.lisp files).  Is there a standard way or package for doing
> > such kind of things or do i need to use the OS calls via FFI.
> 
> (let ((*default-pathname-defaults* "C:\\mystuff\\lisp\\"))
>    (mapcar #'file-namestring (directory "*.lisp")))
> 
> If you want file names, the above does the trick for me using LW on Windows.
> If you want the whole path, leave out the file-namestring part.

This seems to work just fine, too:

CL-USER 4 > (directory "/tmp/*.lisp")
(#P"/tmp/bar.lisp" #P"/tmp/foo.lisp")

CL-USER 5 > (directory "LISP:TEST;*.LISP")
(#P"/home/cartan/src/lisp/test/bingo.lisp"
 #P"/home/cartan/src/lisp/test/blark.lisp")

According to the HyperSpec, the argument to DIRECTORY may contain
wild components (but I am not too sure about the syntax of same).

Regards,
-- 
Nils Goesche
Ask not for whom the <CONTROL-G> tolls.

PGP key ID #xC66D6E6F