On Wed, May 12, 2021 at 9:21 PM Ben Greenman <benjaminlgreen...@gmail.com>
wrote:

> On 5/12/21, Robert Haisfield <roberthhaisfi...@gmail.com> wrote:
> > Daniel, that's awesome. How would I filter down this list according to
> the
> > regex?
> >
> > (define list-of-files (map path->string (directory-list starting-path)))
>
> You can wrap it in a filter:
>
>   (define list-of-files (filter (lambda (str) (regexp-match? "\\.png$"
> str)) (map path->string (directory-list starting-path))))
>

Alternatively, if you would like to keep them as paths instead of strings
then you can do this:

(filter (compose1 (curry regexp-match? "\\.png$") path->string)
(directory-list "."))


Also, if you're going to be doing a lot of work with regexen, take a look
at the at-exp reader so that you don't have to do so much backwhacking
(obviously it's not important in this case where there's only one character
to escape, but it gets helpful as you do more):

#lang at-exp racket
(filter (compose1 (curry regexp-match? @~a{\.png}) path->string)
(directory-list "."))

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAE8gKoe1Nrx%3DU9draN1q%2BokxefrPvH%3D0tq3B8rL5hwAKpXOPRQ%40mail.gmail.com.

Reply via email to