Skip to content

dir

miscellaneous · scripts/miscellaneous/dir.m

: dir
: dir directory
: [list] = dir (directory)

List the contents of a directory.

Without an argument the current directory is listed. Without an output the listing is printed; with an output nothing is printed and a structure array list is returned with one element per entry and the fields

name

the entry’s own name

folder

the absolute path of the directory that holds it

date

the modification time as text

bytes

the size in bytes

isdir

true for a directory

datenum

the modification time as a serial date number

directory may also name a single file, in which case the result describes just that file, or it may contain the wildcards ‘*’, ‘?’ and ‘[]’, in which case every match is described. On POSIX systems a wildcard preceded by a backslash is taken literally; on Windows the backslash separates path components, so a literal wildcard character cannot be requested there and ls should be used instead.

A symbolic link is reported as the file it points to. A dangling link (one whose target does not exist) is reported as the link itself.