sunterlib/scsh/dir-streams/README

92 lines
2.0 KiB
Plaintext
Raw Normal View History

2003-02-20 17:46:41 -05:00
The structure dir-streams defines procedures to represent and process
directories as streams of files and sub-directories.
2003-02-17 07:13:55 -05:00
2003-02-20 17:46:41 -05:00
(dir-stream-from-dir-name dir-name [chase?] [parent]) -> dir-stream
2003-02-17 07:13:55 -05:00
2003-02-20 17:46:41 -05:00
Constructor for dir-streams.
2003-02-17 07:13:55 -05:00
(dir-stream? thing) -> boolean
2003-02-20 17:46:41 -05:00
2003-02-17 07:13:55 -05:00
Type predicate for dir-streams.
(dir-stream-info dir-stream) -> fs-object
Returns the fs-object corresponding to the directory.
2003-02-20 17:46:41 -05:00
2003-02-17 07:13:55 -05:00
(fs-object? thing) -> boolean
Type predicate for file-objects.
2003-02-20 17:46:41 -05:00
2003-02-17 07:13:55 -05:00
(fs-object-parent fs-object) -> string
The parent directory of the fs-object.
(fs-object-name fs-object) -> string
The file name of the fs-object.
(fs-object-info fs-object) -> file-info
The file-info record of the fs-object.
(fs-object-file-name fs-object) -> string
The path to the fs-object.
(dir-stream-files-stream dir-steam) -> fs-object stream
A stream of the fs-objects of the files within the directory.
(dir-stream-subdir-stream dir-stream) -> dir-stream stream
A stream of dir-streams of the subdirectories within the directory.
(dir-stream-filter dir-stream file-pred dir-pred) -> dir-stream
Applies the predicate DIR-PRED to all the subdirectories and FILE-PRED
to all the files within directory. The returned stream contains only
the files and subdirectories for which the predicates return #t.
(dir-stream-fold-right ds make-dir-stream
files-make-stream files-stream-empty
subdirs-make-stream subdirs-empty) -> return type of make-dir-stream
2003-02-20 17:46:41 -05:00
Replaces the constructors of the dir-stream by the supplied procedures.
2003-02-17 07:13:55 -05:00
Example:
(define (disc-usage ds)
(dir-stream-fold-right ds (lambda (fso sum subdirs) (list (fs-object-filename fso)
(apply + sum (map cadr subdirs))
subdirs))
(lambda (fso accu)
(+ accu (file-info:size (fs-object-info fso))))
0
cons
'()))
(dir-stream-map dir-stream-map-f dir-stream file-f dir-f)
TODO argument order
(dir-stream-filter-map dir-stream-map-f dir-stream file-f dir-f)
(dir-stream-for-each dir-stream file-f dir-f)