Documentation

This is machine translation

Translated byMicrosoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

ls

List folder contents

Syntax

Description

lslists the contents of the current folder.

example

lsnamelists the files and folders in the current folder that match the specified name.

example

list= ls(___)returns the names of all the files and folders in the current folder that match the specifiedname. You can specifylistwith any of the arguments in the previous syntaxes.

Examples

collapse all

List Files and Folders

List all the files and folders with names that containmy.

ls*my*
my_class.m my_function.m my_script.m my_text.txt

List all the files and folders with a.mextension.

ls*.m
my_class.m my_function.m my_script.m test_function.m

Save List of Files and Folders

保存所有文件的名称的列表和褶皱ers in the current folder to the variableMyList.

MyList = ls;

Input Arguments

collapse all

name— Name of file or foldercharacter vector

Name of file or folder, specified as a character vector. Use the'*'wildcard to match patterns. For example,ls *.mlists all files and folders with a.mextension, andls m*lists all files and folders with names that begin with the letterm.

Output Arguments

collapse all

list— List of files and folderscharacter array

List of files and folders, specified as a character array in one of these formats.

  • UNIX®platformslistis a character vector of names separated bytabandspacecharacters.

  • Microsoft®Windows®platformslistis anm-by-ncharacter array of names.mis the number of names andnis the number of characters in the longest name. MATLAB®pads names shorter thanncharacters with space characters.

Alternatives

Use thedircommand 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 thefilebrowsercommand.

More About

collapse all

Tips

  • To further modify the results of thelscommand on UNIX platforms, you can add any flags that the operating system supports. For example,ls -cdisplays files by timestamp andls -ddisplays only directories. For more information, see the UNIXlsdocumentation.

See Also

|

Introduced before R2006a

Was this topic helpful?