Did you know ... | Search Documentation: |
![]() | Pack canny_tudor -- prolog/dcg/files.pl |
Finds files and skips the special dot entries. Here, Entry refers to a file. The grammar recursively traverses sub-directories beneath the given Directory and yields every existing file path at Entry. The directory acts as the root of the scan; it joins with the entry to yield the full path of the file, but not with the difference list. The second List argument of phrase/2 unifies with a list of the corresponding sub-path components without the root. The caller sees the full path and the relative sub-components.
Note that the second clause appears in the DCG expanded form with the
two hidden arguments: the pre-parsed input list S0 and the
post-parsed output list S. For non-directory entries, the input list
unifies with nil []
because it represents a terminal node in the
directory tree, and the post-parsed terms amount to the accumulated
Entries spanning the sub-directory entries in-between the original
root directory and the file itself.
No need to check if the Entry exists. It does exist at the time of directory iteration. That could easily change by deleting, moving or renaming the entry.