For more information including compatibility, examples and test cases, see https://github.com/petercrlane/r7rs-libs

1. Directory: (import (robin directory))

This library is implementation specific, providing a common interface for working with directories.

1.1. change-directory

change-directory changes the current working directory to the given directory.

1.2. current-directory

current-directory returns the current working directory (as a string):

#|kawa:1|# (import (robin directory))
#|kawa:2|# (current-directory)
/home/peter/Software/r7rs-libs/robin

1.3. delete-directory

delete-directory deletes the given directory.

1.4. list-directory

list-directory returns a list of all files and directories in the given directory:

#|kawa:3|# (list-directory ".")
(pfds announce.txt robin-examples pfds-tests weinholt robin r7rs-libs.jar r6rs
 pfds-examples build-kawa.sh autodiff-examples nltk-tests rebottled INSTALL.md
 slib run-tests.sh nltk-examples weinholt-tests slib-examples srfis .gitignore
 LICENSE.md .git rebottled-tests jacal robin-tests build-kawa-win.bat bin
 rebottled-examples nltk doc autodiff slib-tests README.md jacal.sh jacal-tests
 autodiff-tests)

1.5. list-directory-files

list-directory-files returns a list of the filenames in the given directory:

#|kawa:3|# (list-directory-files ".")
(announce.txt r7rs-libs.jar build-kawa.sh INSTALL.md run-tests.sh .gitignore
 LICENSE.md build-kawa-win.bat README.md jacal.sh)

Giving #t as the optional second argument returns a list of the pathnames of files in the given directory:

#|kawa:4|# (list-directory-files "." #t)
(/home/peter/Software/r7rs-libs/announce.txt
 /home/peter/Software/r7rs-libs/r7rs-libs.jar
 /home/peter/Software/r7rs-libs/build-kawa.sh
 /home/peter/Software/r7rs-libs/INSTALL.md
 /home/peter/Software/r7rs-libs/run-tests.sh
 /home/peter/Software/r7rs-libs/.gitignore
 /home/peter/Software/r7rs-libs/LICENSE.md
 /home/peter/Software/r7rs-libs/build-kawa-win.bat
 /home/peter/Software/r7rs-libs/README.md
 /home/peter/Software/r7rs-libs/jacal.sh)

1.6. list-glob

list-glob returns all files matching the given glob. A glob is matched using slib’s filename:match??.

#|kawa:5|# (list-glob "**/*.txt")
(/home/peter/Software/r7rs-libs/doc/logger.txt
 /home/peter/Software/r7rs-libs/doc/statistics.txt
 /home/peter/Software/r7rs-libs/doc/slib.txt
 /home/peter/Software/r7rs-libs/doc/r7rs.txt
 /home/peter/Software/r7rs-libs/doc/summary.txt
 /home/peter/Software/r7rs-libs/doc/series.txt
 /home/peter/Software/r7rs-libs/doc/srfi64-utils.txt
 /home/peter/Software/r7rs-libs/doc/repackaged.txt
 /home/peter/Software/r7rs-libs/doc/disjoint-set.txt
 /home/peter/Software/r7rs-libs/doc/constants.txt
 /home/peter/Software/r7rs-libs/doc/abbrev.txt
 /home/peter/Software/r7rs-libs/doc/directory.txt
 /home/peter/Software/r7rs-libs/doc/subdata.txt
 /home/peter/Software/r7rs-libs/doc/text.txt
 /home/peter/Software/r7rs-libs/doc/alldata.txt
 /home/peter/Software/r7rs-libs/rebottled-examples/examples.txt
 /home/peter/Software/r7rs-libs/robin-tests/output.txt
 /home/peter/Software/r7rs-libs/robin-tests/voc.txt
 /home/peter/Software/r7rs-libs/jacal/files.txt
 /home/peter/Software/r7rs-libs/announce.txt)

1.7. make-directory

make-directory creates a directory with the given name:

#|kawa:6|# (make-directory "test-directory")

1.8. Example: Count lines of Scheme code

The program "scmcount.sps" in "robin-examples" illustrates using some of these functions to scan through all child directories from a given directory for Scheme files. The number of code lines in each file is then counted, and a list displayed of the full file paths and the counts.

(define (collect-information directory)
  (let ((current (current-directory)))
    (guard (err (else (display err))) ; ignore any errors - e.g. permission errors
           (change-directory directory)                                             ; <1>
           (let ((chop (+ 1 (string-length (current-directory)))))
             (list-glob "**/*.s?*"                                                  ; <2>
                        (lambda (filename) ; chop starts directory from filename
                          (update-information (string-copy filename chop))))        ; <3>
             (change-directory current)))))                                         ; <4>
  1. Move to the given directory

  2. Search for potential Scheme source files in any child directory

  3. Gather information about each potential Scheme file

  4. And return to the original directory

 $ sagittarius -L . -L srfis/sagittarius/ robin-examples/scmcount.sps rebottled
 --------------------------
 cl-pdf-utils.sld    334
       cl-pdf.sld    315
  json-parser.sld    306
  json-select.sld    270
   json-tools.sld    407
      packrat.sld    269
      pregexp.sld    675
   quaternion.sld    286
      schelog.sld    518
 --------------------------
 Total files: 9
 Total lines: 3380