unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* here is one way to implement file globbing
@ 2018-10-15 23:12 tantalum
  2018-10-16 15:12 ` Amirouche Boubekki
  0 siblings, 1 reply; 2+ messages in thread
From: tantalum @ 2018-10-15 23:12 UTC (permalink / raw)
  To: guile-user

im sure it is not the optimal way to do it, and currently it fails on 
file access errors and there might be bugs, but it has cool features and 
i just wanted to share.
filesystem globbing is the matching of paths that can include wildcard 
characters like asterisks.

the code implements the following:

filesystem-glob :: string -> (string ...)

   find files matching a file system path with optional wildcard 
characters.
   * matches zero or more of any character in a file name.
   ? matches one of any character in a file name.
   ** skips any sub directories to match the rest of the path. at the end 
of a path it is the same as **/.* including .*
   **n where n is an integer. like ** but skips directories at most n sub 
directories deep.
   example patterns
     a/b/*
     *.txt
     a/**/c/*.txt
     a/**
     **/*.txt
     a/**2/*

to list all files in a directory recursively: dir/**
and to list all pdf files in a directory recursively: dir/**/*.pdf

here is the code with reduced dependencies so that anybody with only 
guile should be able to run it:
http://files.sph.mn/s/computer/guile-fsg.scm

it is now part of sph-lib: 
https://github.com/sph-mn/sph-lib/blob/master/modules/sph/filesystem.scm

you can play around with it on the command-line by creating an 
executable file with content similar to this:

#!/usr/bin/guile
!#

(include "guile-fsg.scm")

(for-each (lambda (a) (display a) (newline))
   (filesystem-glob (car (cdr (program-arguments)))))


if this is in a file "mygl" then you can call it like "./mygl '/tmp/*'". 
paths in single quotes, otherwise the shell evaluates the wildcards.



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-10-16 15:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-15 23:12 here is one way to implement file globbing tantalum
2018-10-16 15:12 ` Amirouche Boubekki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).