| MATLAB Function Reference | ![]() |
As an alternative to the dir function, use the Current Directory Browser.
dir
dir name
files = dir('dirname')
dir lists the files in the current working directory. Results are not sorted, but presented in the order returned by the operating system.
dir name lists the specified files. The name argument can be a pathname, filename, or can include both. You can use absolute and relative pathnames and wildcards (*).
files = dir('dirname') returns the list of files in the specified directory (or the current directory, if dirname is not specified) to an m-by-1 structure with the fields.
Fieldname | Description | Data Type |
|---|---|---|
| name | Filename | char array |
| date | Modification date timestamp | char array |
| bytes | Number of bytes allocated to the file | double |
| isdir | 1 if name is a directory; 0 if not | logical |
| datenum | Modification date as serial date number | double |
On Windows® systems, obtain a list of drives available using the DOS net use command. In the Command Window, run
dos('net use')Or run
[s,r] = dos('net use')to return the results to the character array r.
The MATLAB® dir function is consistent with the Microsoft® Windows OS dir command in that both support short filenames generated by DOS. For example, both of the following commands are equivalent in both Windows and MATLAB:
dir long_matlab_mfile_name.m long_matlab_mfile_name.m dir long_m~1.m long_matlab_m-file_name.m
To view the contents of the matlab/audiovideo directory, type
dir(fullfile(matlabroot, 'toolbox/matlab/audiovideo'))
To view the MAT files in your current working directory that include the term java, type
dir *java*.mat
MATLAB returns all filenames that match this specification:
java_array.mat javafrmobj.mat testjava.mat
To view the M-files in the MATLAB audiovideo directory, type
dir(fullfile(matlabroot,'toolbox/matlab/audiovideo/*.m'))
MATLAB returns
Contents.m aviinfo.m render_uimgraudiotoolbar.m audiodevinfo.m aviread.m sound.m audioplayerreg.m lin2mu.m soundsc.m audiorecorderreg.m mmcompinfo.m wavfinfo.m audiouniquename.m mmfileinfo.m wavplay.m aufinfo.m movie2avi.m wavread.m auread.m mu2lin.m wavrecord.m auwrite.m prefspanel.m wavwrite.m avifinfo.m render_fullaudiotoolbar.m
To return the list of files to the variable av_files, type
av_files = dir(fullfile(matlabroot, ...
'toolbox/matlab/audiovideo/*.m'))MATLAB returns the information in a structure array.
av_files =
24x1 struct array with fields:
name
date
bytes
isdir
datenumIndex into the structure to access a particular item. For example,
av_files(3).name ans = audioplayerreg.m
cd, copyfile, delete, fileattrib, filebrowser, fileparts, genpath, isdir, ls, matlabroot, mkdir, mfilename, movefile, rmdir, type, what
![]() | diffuse | dir (ftp) | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |