FileTools
Walk
generate iterator to traverse subdirectories under a given directory
Calling Sequence
Parameters
Options
Description
Iterator Objects
Examples
Compatibility
Walk(dir, traversal, opts)
dir
-
path to the base of the directory structure to be traversed
traversal
(optional) one of the symbols topdown or bottomup
opts
(optional) arguments of the form option=value where option is one of base, followlinks, remove or select.
base=one of bindir, datadir, homedir, mapledir, tempdir, toolboxdir, worksheetdir.
The base option specifies a base directory. If specified, the parameter dir is interpreted as a relative path under this directory. For the meaning of worksheetdir see interface; for any other of these symbols, see kernelopts.
followlinks=truefalse
Indicates whether the traversal will follow symbolic links and traverse the subdirectories underneath the link destination. When false, a symbolic link which points to a directory will appear in the files field of the record corresponding to its parent directory and not the subdirs field. The default value is false.
remove=string
The remove option is used to remove elements from the list of filenames. Only the filenames that do not match the pattern specified in the string are returned by the iterator. The pattern must conform to the form defined by StringTools[WildcardMatch].
select=string
The select option is used to select elements from the list of filenames. Only the filenames that match the pattern specified in the string are returned by the iterator. The pattern must conform to the form defined by StringTools[WildcardMatch].
The Walk(dir, traversal, opts) command returns an iterator object which can be used to traverse the subdirectories under the file path dir.
The path dir must correspond to an existing directory. It can be relative or absolute; if relative, it is interpreted as relative to the current directory as reported by currentdir.
With each step, the iterator object will return a record with three fields: dir, subdirs, and files.
dir is the path of a directory within the hierarchy rooted at dir,
subdirs is the list of subdirectories within dir,
files is the list of files within dir.
The optional parameter traversal specifies the type of traversal. Permissible values are topdown which means that the record for a directory will be returned before any of its subdirectories, or bottomup which means that the record for a directory will be generated after all of its subdirectories.
The iterator object is an Iterator with hasNext and getNext methods as defined by the Iterator API.
The state of an iterator object iter may be reset to the beginning of the iteration by invoking Reset(iter).
iterator≔FileToolsWalk⁡/home/someuser
FileTools:-Walk IteratorBase directory: /home/someuserTraversal: top-down
forriniteratordoprint⁡r:-dir,r:-subdirs,r:-filesenddo
/home/someuser,docs,images,somefile.txt
/home/someuser/docs,,doc1.docx,doc2.txt
/home/someuser/images,,bird.jpg,tree.jpg
The FileTools[Walk] command was introduced in Maple 2020.
For more information on Maple 2020 changes, see Updates in Maple 2020.
The FileTools[Walk] command was updated in Maple 2024.
The remove and select options were introduced in Maple 2024.
For more information on Maple 2024 changes, see Updates in Maple 2024.
See Also
FileTools[ListDirectory]
ModuleIterator
Download Help Document