From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: tantalum Newsgroups: gmane.lisp.guile.user Subject: here is one way to implement file globbing Date: Mon, 15 Oct 2018 23:12:43 +0000 Message-ID: <92c495d8442433c77df97732730ae60c@posteo.de> Reply-To: sph@posteo.eu NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1539645076 1811 195.159.176.226 (15 Oct 2018 23:11:16 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 15 Oct 2018 23:11:16 +0000 (UTC) User-Agent: Posteo Webmail To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Tue Oct 16 01:11:11 2018 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gCC0z-0000Hy-JR for guile-user@m.gmane.org; Tue, 16 Oct 2018 01:11:09 +0200 Original-Received: from localhost ([::1]:55232 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCC31-0005BY-65 for guile-user@m.gmane.org; Mon, 15 Oct 2018 19:13:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45873) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCC2e-00059V-Rv for guile-user@gnu.org; Mon, 15 Oct 2018 19:12:53 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gCC2Z-0001KA-OW for guile-user@gnu.org; Mon, 15 Oct 2018 19:12:52 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:33457) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gCC2Z-0001Gl-2z for guile-user@gnu.org; Mon, 15 Oct 2018 19:12:47 -0400 Original-Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 493BF2400FB for ; Tue, 16 Oct 2018 01:12:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.eu; s=2017; t=1539645164; bh=4PHTPZGuiLSTMpKwYfZvi86v7YuhX6G8ipCKnC4esEE=; h=Date:From:To:Subject:From; b=iRb+3jOjihMBlPB6UNPLUW2QpAcR4sK9zJnFl+0r0/rbnbq7elGnkmwS34q4o1MSC VtPOlPMj1prjcFmwXzTFfA4LAmhmfT3Y1njctYi7HvsrF9LnvrCw1x4xNS7fMgSfp8 m0ksKHHLCuMm7xH992dnRw8MavjXkxk2TUynLT+Gr/f6dA0yUnyCDLjc3rzhLuHFfD nZHd5iJqDdDkWG+FPxp7rJwUVAbE1JQnzB8dil4C+CDRcjlI0rxH0ygR7w5UKGpWib G0BHmr2O80cDQIIpkDn8XWvmh3H9ZwgLgqYKlnxfNx5eIPlJJNYpup4RMQ4Fkbi4JD kMXVSb5tsPeNg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 42YvNq6kYwz9rxG for ; Tue, 16 Oct 2018 01:12:43 +0200 (CEST) Mail-Reply-To: sph@posteo.eu X-Sender: sph@posteo.eu X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.67.36.66 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:14932 Archived-At: 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.