List folder contents
dir
lists files and folders in the current
folder.
dir
lists files and folders that match
name
name
. When name
is a folder,
dir
lists the contents of the folder. Specify
name
using absolute or relative path names. The
name
argument can include the *
wildcard in the file name, and both the *
and the
**
wildcard in the path name. Characters next to a
**
wildcard must be file separators.
To exclude invalid entries returned by the dir
command,
use the cellfun
function.
MyFolderInfo = dir;
MyFolderInfo = MyFolderInfo(~cellfun('isempty', {MyFolderInfo.date}));
Invalid entries occur when you run dir
with
an output argument and the results include a nonexistent file or a
file that dir
cannot query for some other reason.
In this case, dir
returns the following default
values.
date: '' bytes: [] isdir: 0 datenum: []
Invalid entries most commonly occur on UNIX® platforms when dir
queries
a symbolic link pointing to a nonexistent target. A nonexistent target
is a target that is moved, removed, or renamed.
To obtain a list of available drives on Microsoft Windows platforms,
use the DOS net use
command at the command line.
dos('net use')
Or type
[s,r] = dos('net use')
MATLAB returns the results to the character array r
.