<RefEntry id="directory-depth">
<!-- This file is generated automatically from the DSSSL source. -->
<!-- Do not edit this file! -->
<?html-filename directory-depth.html>

<RefMeta>
  <RefEntryTitle>directory-depth</RefEntryTitle>
  <RefMiscInfo Role="file">dblib.dsl</RefMiscInfo>
</RefMeta>

<RefNameDiv>
  <RefName>directory-depth</RefName>
  <RefPurpose>Count the directory depth of a path name</RefPurpose>
</RefNameDiv>

<RefSynopsisDiv><Title>Synopsis</Title>
<Synopsis>
(directory-depth pathname)
</Synopsis>
</RefSynopsisDiv>

<RefSect1><Title>Description</Title>

<para>
Returns the number of directory levels in <literal>pathname</literal>
</para>
<para>
The pathname must end in a filename.
Further, this function assumes that directories in a pathname are 
separated by forward slashes ("/").</para>


</RefSect1>

<RefSect1><Title>Example</Title>

<para>
"filename" => 0, 
"foo/filename" => 1, 
"foo/bar/filename => 2, 
"foo/bar/../filename => 1.
</para>


</RefSect1>

<RefSect1><Title>Author</Title>

<para>
Norman Walsh, &lt;ndw@nwalsh.com&gt;
</para>
</RefSect1>
<RefSect1><Title>Source Code</Title>

<ProgramListing>
(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)))))))
</ProgramListing>
</RefSect1>

</RefEntry>
