user11405017
user11405017

Reputation:

Is there a easy way to get the "directory" function to put the values in alphabetical order?

Retrieving all paths for the files with .pas ending in my subfolder "testfiles" with the directory function. So far so good. The problem is that the paths is not in alphabetical order.

The paths in the list is not strings or list, so the sort function does not work for me either.

Is there a easy way to fix this?

Code:

(setq test (directory "testfiles/*.pas"))

Upvotes: 1

Views: 159

Answers (1)

Bruno Haible
Bruno Haible

Reputation: 1282

The sequence functions in Common Lisp are powerful, through the various keyword parameters (:key, :test, etc., depending on the function). SORT takes an optional :key parameter.

(sort (directory "testfiles/*.pas") #'string< :key #'pathname-name)

Note: SORT is a destructive operation. But this is not a problem here, because DIRECTORY always returns a freshly consed-up list.

Upvotes: 2

Related Questions