unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: tantalum <sph@posteo.eu>
To: guile-user@gnu.org
Subject: here is one way to implement file globbing
Date: Mon, 15 Oct 2018 23:12:43 +0000	[thread overview]
Message-ID: <92c495d8442433c77df97732730ae60c@posteo.de> (raw)

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.



             reply	other threads:[~2018-10-15 23:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-15 23:12 tantalum [this message]
2018-10-16 15:12 ` here is one way to implement file globbing Amirouche Boubekki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=92c495d8442433c77df97732730ae60c@posteo.de \
    --to=sph@posteo.eu \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).