Re: proper use of "directory"

On 26 čnc, 20:01, Vinay <vmco...@xxxxxxxxx> wrote:
i need to have a list of the files in a directory, and am trying to do
it like this :

(defun load-all-files (in-dir)
  (directory (make-pathname :name :wild :type :wild :defaults in-

it works fine for directories with a few files.

for the problem i'm working on, this directory contains thousands of
files (> 20,000). in this scenario, it seems to take for ever.

is there a better way to use directory ? some way for it to stream the
contents of the directory, rather than cons'ing up a list ?


Hello Vinay,

Regardless of the fact that you are using CL, in some cases you could
make advantage of the already existing file database. I have good
experience with using mlocate.db file on Linux - this service usually
runs anyway on my machine and the file is rather easy to parse (I
could find the parser if you want to see, but it is not cleaned up).
Even calling updatedb manually on directory tree may be faster than
reading the tree in lisp (as updatedb does not need to scan
directories that did not change since last scan).

It depends on your usage scenario, of course, and may be not
appropriate for you.

With regards,