Walk - Maple Help

FileTools

 Walk
 generate iterator to traverse subdirectories under a given directory

 Calling Sequence Walk(dir, traversal, opts)

Parameters

 dir - path to the base of the directory structure to be traversed traversal - (optional) one of the symbols topdown or bottomup opts - (optional) argument of the form option or option=value where option is one of followlinks.

Options

 • 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.
 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.

Description

 • 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.

Iterator Objects

 • 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).

Examples

 > $\mathrm{iterator}≔\mathrm{FileTools}\left[\mathrm{Walk}\right]\left("/home/someuser"\right)$
 $\left[\begin{array}{c}{\mathrm{FileTools:-Walk Iterator}}\\ {\mathrm{Base directory: /home/someuser}}\\ {\mathrm{Traversal: top-down}}\end{array}\right]$ (1)
 > $\mathbf{for}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}r\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{iterator}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}\mathrm{print}\left(r:-\mathrm{dir},r:-\mathrm{subdirs},r:-\mathrm{files}\right)\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\mathbf{end}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}$
 ${"/home/someuser"}{,}\left[{"docs"}{,}{"images"}\right]{,}\left[{"somefile.txt"}\right]$
 ${"/home/someuser/docs"}{,}\left[\right]{,}\left[{"doc1.docx"}{,}{"doc2.txt"}\right]$
 ${"/home/someuser/images"}{,}\left[\right]{,}\left[{"bird.jpg"}{,}{"tree.jpg"}\right]$ (2)

Compatibility

 • The FileTools[Walk] command was introduced in Maple 2020.