List folder contents
ls lists the contents of the current folder.
List Files and Folders
List all the files and folders with names that contain
my_class.m my_function.m my_script.m my_text.txt
List all the files and folders with a
my_class.m my_function.m my_script.m test_function.m
Save List of Files and Folders
Save a list of the names of all the files and
folders in the current folder to the variable
MyList = ls;
name — Name of file or folder
character vector | string scalar
Name of file or folder, specified as a character vector or string scalar. Use the
'*' wildcard to match patterns. For example,
ls *.m lists all files and folders with a
.m extension, and
ls m* lists all
files and folders with names that begin with the letter
list — List of files and folders
List of files and folders, specified as a character array in one of these formats.
UNIX® platforms –
listis a character vector of names separated by tab and space characters.
Microsoft® Windows® platforms –
ncharacter array of names.
mis the number of names and
nis the number of characters in the longest name. MATLAB® pads names shorter than
ncharacters with space characters.
To further modify the results of the
lscommand on UNIX platforms, you can add any flags that the operating system supports. For example,
ls -cdisplays files by timestamp and
ls -ddisplays only directories. For more information, see the UNIX
dir command to
return file attributes for each file and folder in the output argument.
You can also view files and folders in the Current Folder browser by issuing the
Introduced before R2006a