For more information including compatibility, examples and test cases, see

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)

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 autodiff-examples nltk-tests rebottled
 slib nltk-examples weinholt-tests slib-examples srfis .gitignore .git rebottled-tests jacal robin-tests build-kawa-win.bat bin
 rebottled-examples nltk doc autodiff slib-tests jacal-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 .gitignore build-kawa-win.bat

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)

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")

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