Walk - Maple Help

Online Help

All Products    Maple    MapleSim


FileTools

  

Walk

  

generate iterator to traverse subdirectories under a given directory

 

Calling Sequence

Parameters

Options

Description

Iterator Objects

Examples

Compatibility

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.

• 

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.

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

iteratorFileToolsWalk/home/someuser

FileTools:-Walk IteratorBase directory: /home/someuserTraversal: top-down

(1)

forriniteratordoprintr:-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

(2)

Compatibility

• 

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

• 

For more information on Maple 2020 changes, see Updates in Maple 2020.

See Also

FileTools

FileTools[ListDirectory]

ModuleIterator