dir
Directory listing of the current or specified directory.
Syntax
dir
dir(dirname)
R = dir
R = dir(dirname)
Inputs
- dirname (optional)
- Path to directory.
Outputs
- R (if specified)
- If nargout is 0, a list of directories and files is displayed.
Examples
(nargout
0):
dir('c:\tests')
.
..
test1.txt
test2.txt
(nargout
1):
dir_result = dir('c:\tests'); % dir output is saved as a struct in the variable.
% for each element in the struct display:
% file or <dir>, name size and date.
for i = 1:size(dir_result)(1)
if dir_result(i).isdir
type_string = '<dir>'
else
type_string = 'file';
end
printf('%s #%d name: %-15s size: %6d date: %s',
type_string, % display file or <dir>
i,
dir_result(i).name, %display name
dir_result(i).bytes, %display size
dir_result(i).date) % display date
end
<dir> #1 name: . size: 0 date: Feb-11-2016 18:24:20
<dir> #2 name: .. size: 0 date: Feb-11-2016 18:24:20
file #3 name: test1.txt size: 5838 date: Feb-11-2016 18:24:8
file #4 name: test2.txt size: 7 date: Feb-11-2016 18:24:20