ListDirectory - Maple Help

FileTools

 ListDirectory
 display the contents of a directory

 Calling Sequence ListDirectory(dir, opts )

Parameters

 dir - path to the directory to be displayed opts - (optional) argument of the form option or option=value where option is one of absolute, all, base, long, recurse, or returnonly

Options

 • ListDirectory accepts these optional arguments: absolute, all, base, depth, long, recurse, and returnonly.
 • absolute=truefalse
 Specifying absolute=true causes ListDirectory to return absolute paths for all listed files (see AbsolutePath). With the default value absolute=false, only the filenames themselves are returned.
 • all=truefalse
 By default, ListDirectory does not include filenames that begin with "." in its list of results. Specifying the all option causes ListDirectory to include these files.
 • 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.
 • depth=posint or infinity
 Specifying depth with a value other than 1 causes ListDirectory to recursively traverse the complete directory tree starting with dir to the depth specified by depth.
 Note that if depth is set to a value other than 1, the value of option absolute is implicitly set to true, and the special directories "." and ".." will not appear in the list of results even if all=true was specified.
 Specifying depth=infinity is equivalent to specifying recurse=true.
 • long=truefalse
 Specifying long causes ListDirectory to returns a DataFrame structure which contains the name together with additional properties about each file, including size, whether or not the file is a directory, access permissions, and last modification date. The default is false.
 • recurse=truefalse
 Specifying recurse=true causes ListDirectory to recursively traverse the complete directory tree starting with dir. The default is false.
 Note that if recurse=true, the value of option absolute is set to true, and the special directories "." and ".." will not appear in the list of results even if all=true was specified.
 Specifying recurse=true is equivalent to specifying depth=infinity.
 • returnonly=string
 The returnonly option is used to select elements from the list of filenames. Only the filenames that match the pattern specified in the string are returned. The pattern must conform to the form defined by StringTools[WildcardMatch].

Description

 • The ListDirectory(dir) calling sequence returns the contents of the directory dir as a list.
 • If dir does not exist, ListDirectory generates an error.
 • If dir is not a directory, ListDirectory generates an error.
 • For information on filenames, see file.

Examples

 > $\mathrm{DataDirectory}≔\mathrm{FileTools}\left[\mathrm{JoinPath}\right]\left(\left["data"\right],\mathrm{base}=\mathrm{mapledir}\right)$
 ${\mathrm{DataDirectory}}{≔}{"/maple/cbat/active/169462/data"}$ (1)
 > $\mathrm{FileTools}\left[\mathrm{ListDirectory}\right]\left(\mathrm{DataDirectory}\right)$
 $\left[{"CAD"}{,}{"Excel"}{,}{"FMUs"}{,}{"GroupData"}{,}{"SQLite"}{,}{"Start_el.mw"}{,}{"Start_es.mw"}{,}{"Start_fr.mw"}{,}{"Start_hu.mw"}{,}{"Start_ko.mw"}{,}{"Start_pt_BR.mw"}{,}{"Start_zh_CN.mw"}{,}{"Start_zh_TW.mw"}{,}{"ThermophysicalData"}{,}{"Workbook"}{,}{"assistants"}{,}{"audio"}{,}{"datasets"}{,}{"dsolve"}{,}{"eBookTools"}{,}{"example"}{,}{"finance"}{,}{"help"}{,}{"images"}{,}{"ks.txt"}{,}{"plotting"}{,}{"portal"}{,}{"q"}{,}{"sigpro"}{,}{"stylesets"}{,}{"tutors"}{,}{"videos"}{,}{"xls"}{,}{"xml"}{,}{"xsl"}{,}{"zoneinfo"}{,}{"StudyGuides"}{,}{"Start.mw"}\right]$ (2)
 > $\mathrm{FileTools}\left[\mathrm{ListDirectory}\right]\left(\mathrm{DataDirectory},'\mathrm{all}'\right)$
 $\left[{"."}{,}{".."}{,}{"CAD"}{,}{"Excel"}{,}{"FMUs"}{,}{"GroupData"}{,}{"SQLite"}{,}{"Start_el.mw"}{,}{"Start_es.mw"}{,}{"Start_fr.mw"}{,}{"Start_hu.mw"}{,}{"Start_ko.mw"}{,}{"Start_pt_BR.mw"}{,}{"Start_zh_CN.mw"}{,}{"Start_zh_TW.mw"}{,}{"ThermophysicalData"}{,}{"Workbook"}{,}{"assistants"}{,}{"audio"}{,}{"datasets"}{,}{"dsolve"}{,}{"eBookTools"}{,}{"example"}{,}{"finance"}{,}{"help"}{,}{"images"}{,}{"ks.txt"}{,}{"plotting"}{,}{"portal"}{,}{"q"}{,}{"sigpro"}{,}{"stylesets"}{,}{"tutors"}{,}{"videos"}{,}{"xls"}{,}{"xml"}{,}{"xsl"}{,}{"zoneinfo"}{,}{"StudyGuides"}{,}{"Start.mw"}\right]$ (3)
 > $\mathrm{FileTools}\left[\mathrm{ListDirectory}\right]\left(\mathrm{DataDirectory},'\mathrm{all}','\mathrm{returnonly}'="f*"\right)$
 $\left[{"finance"}\right]$ (4)
 > $\mathrm{FileTools}\left[\mathrm{ListDirectory}\right]\left(\mathrm{DataDirectory},'\mathrm{returnonly}'="*\left[ae\right]*"\right)$
 $\left[{"Excel"}{,}{"GroupData"}{,}{"SQLite"}{,}{"Start_el.mw"}{,}{"Start_es.mw"}{,}{"Start_fr.mw"}{,}{"Start_hu.mw"}{,}{"Start_ko.mw"}{,}{"Start_pt_BR.mw"}{,}{"Start_zh_CN.mw"}{,}{"Start_zh_TW.mw"}{,}{"ThermophysicalData"}{,}{"assistants"}{,}{"audio"}{,}{"datasets"}{,}{"dsolve"}{,}{"eBookTools"}{,}{"example"}{,}{"finance"}{,}{"help"}{,}{"images"}{,}{"portal"}{,}{"stylesets"}{,}{"videos"}{,}{"zoneinfo"}{,}{"StudyGuides"}{,}{"Start.mw"}\right]$ (5)
 > $\mathrm{FileTools}\left[\mathrm{ListDirectory}\right]\left(\mathrm{DataDirectory},'\mathrm{all}','\mathrm{returnonly}'="*\left[ae\right]*"\right)$
 $\left[{"Excel"}{,}{"GroupData"}{,}{"SQLite"}{,}{"Start_el.mw"}{,}{"Start_es.mw"}{,}{"Start_fr.mw"}{,}{"Start_hu.mw"}{,}{"Start_ko.mw"}{,}{"Start_pt_BR.mw"}{,}{"Start_zh_CN.mw"}{,}{"Start_zh_TW.mw"}{,}{"ThermophysicalData"}{,}{"assistants"}{,}{"audio"}{,}{"datasets"}{,}{"dsolve"}{,}{"eBookTools"}{,}{"example"}{,}{"finance"}{,}{"help"}{,}{"images"}{,}{"portal"}{,}{"stylesets"}{,}{"videos"}{,}{"zoneinfo"}{,}{"StudyGuides"}{,}{"Start.mw"}\right]$ (6)
 > $\mathrm{FileTools}\left[\mathrm{ListDirectory}\right]\left("/home/maple/m/foo1.m"\right)$
 > $\mathrm{FileTools}\left[\mathrm{ListDirectory}\right]\left("/home/maple/noexist"\right)$

Compatibility

 • The depth, long and recurse options were introduced in Maple 2018.