FileTools
ListDirectory
display the contents of a directory
Calling Sequence
Parameters
Options
Description
Examples
Compatibility
ListDirectory(dir, opts )
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
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].
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.
DataDirectory ≔ FileToolsJoinPath⁡data,base=mapledir
DataDirectory≔/maple/cbat/active/234548/data
FileToolsListDirectory⁡DataDirectory
CAD,Excel,FMUs,GroupData,SQLite,Start.mw,StudyGuides,ThermophysicalData,Workbook,assistants,audio,datasets,dsolve,eBookTools,example,finance,help,images,ks.txt,plotting,portal,q,sigpro,stylesets,tutors,videos,xls,xml,xsl,zoneinfo
FileToolsListDirectory⁡DataDirectory,'all'
.,..,CAD,Excel,FMUs,GroupData,SQLite,Start.mw,StudyGuides,ThermophysicalData,Workbook,assistants,audio,datasets,dsolve,eBookTools,example,finance,help,images,ks.txt,plotting,portal,q,sigpro,stylesets,tutors,videos,xls,xml,xsl,zoneinfo
FileToolsListDirectory⁡DataDirectory,'all','returnonly'=f*
finance
FileToolsListDirectory⁡DataDirectory,'returnonly'=*[ae]*
Excel,GroupData,SQLite,Start.mw,StudyGuides,ThermophysicalData,assistants,audio,datasets,dsolve,eBookTools,example,finance,help,images,portal,stylesets,videos,zoneinfo
FileToolsListDirectory⁡DataDirectory,'all','returnonly'=*[ae]*
FileToolsListDirectory⁡/home/maple/m/foo1.m
Error, (in listdir) directory does not exist
FileToolsListDirectory⁡/home/maple/noexist
Error, (in isdir) file or directory does not exist
The depth, long and recurse options were introduced in Maple 2018.
For more information on Maple 2018 changes, see Updates in Maple 2018.
The FileTools[ListDirectory] command was updated in Maple 2020.
The base option was introduced in Maple 2020.
For more information on Maple 2020 changes, see Updates in Maple 2020.
See Also
file
FileTools[AbsolutePath]
FileTools[Binary][Open]
FileTools[IsDirectory]
FileTools[Text][Open]
IO_errors
StringTools[WildcardMatch]
Download Help Document