Skip to content

dir

List files in a directory.

dir
dir(name)
files = dir(name)

Lists the files and subdirectories in name (or the current directory if no argument). Wildcards (*, ?) are supported.

With an output assignment, returns a struct array — one element per matched file — with fields name, folder, date, bytes, isdir, datenum. Without output assignment, prints the listing.

dir % list current directory
dir('*.csv') % list all CSV files
files = dir('data/'); % capture as struct array
  • cd — Change the current working directory.
  • exist — Check whether a name exists in the workspace, on disk, or as a built-in.
  • mkdir — Create a directory.
  • rmdir — Remove a directory.