| The Modular DocBook Stylesheets | ||
|---|---|---|
| Prev | DSSSL Library | Next |
(directory-depth pathname)
Returns the number of directory levels in pathname
The pathname must end in a filename. Further, this function assumes that directories in a pathname are separated by forward slashes ("/").
"filename" => 0, "foo/filename" => 1, "foo/bar/filename => 2, "foo/bar/../filename => 1.
Norman Walsh, <norm@berkshire.net>
(define (directory-depth pathname)
;; Count the directory depth of a path name
(let loop ((count 0) (pathlist (match-split pathname "/")))
(if (null? pathlist)
(- count 1) ;; pathname should always end in a filename
(if (or (equal? (car pathlist) "/") (equal? (car pathlist) "."))
(loop count (cdr pathlist))
(if (equal? (car pathlist) "..")
(loop (- count 1) (cdr pathlist))
(loop (+ count 1) (cdr pathlist)))))))| Prev | Home | Next |
| dingbat | Up | expand-children |
Copyright © 1997, 1998 Norman Walsh