List folder contents - MATLAB dir - MathWorks France (2024)

List folder contents

collapse all in page

Syntax

dir

dir name

listing = dir(name)

Description

dir lists files and folders in the currentfolder.

example

dir name lists files and folders that match 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.

example

listing = dir(name) returnsattributes about name.

Examples

View Contents of Folder

List the contents of a folder.

Create a folder, myfolder, that contains the files myfile1.m, myfile2.m, and myfile3.m.

mkdir myfoldermovefile myfile1.m myfoldermovefile myfile2.m myfoldermovefile myfile3.m myfolder

List the files in myfolder.

dir myfolder
. .. myfile1.m myfile2.m myfile3.m 

Find Files Matching Specified Name

List all files with a .m extension that contain the term my.

Create a folder, myfolder, that contains the files myfile1.m, myfile2.m, and myfile3.txt.

mkdir myfoldermovefile myfile1.m myfoldermovefile myfile2.m myfoldermovefile myfile3.txt myfolder

List the matching files in myfolder.

myfile1.m myfile2.m 

Find Files in Subfolders

List all files in the current folder and all of the subfolders of the current folder.

Create a folder, myfolder1, that contains these files and folders:

myfile1.mmyfolder2 myfile2.m myfolder3 myfile3.m
mkdir myfolder1mkdir myfolder1/myfolder2mkdir myfolder1/myfolder2/myfolder3movefile myfile1.m myfolder1movefile myfile2.m myfolder1/myfolder2movefile myfile3.m myfolder1/myfolder2/myfolder3

List all files with a .m extension in myfolder1 and all of the subfolders of myfolder1.

cd myfolder1dir **/*.m
Files Found in Current Folder:myfile1.m Files Found in: myfolder2myfile2.m Files Found in: myfolder2\myfolder3myfile3.m 

Find Information in the Return Structure

Return the folder listing of myfolder to the variable MyFolderInfo.

Create a folder, myfolder, that contains the files myfile1.m, myfile2.m, and myfile3.m.

mkdir myfoldermovefile myfile1.m myfoldermovefile myfile2.m myfoldermovefile myfile3.m myfolder

Get a list of the files in myfolder. MATLAB® returns the information in a structure array.

MyFolderInfo = dir('myfolder')
MyFolderInfo=5×1 struct array with fields: name folder date bytes isdir datenum

Index into the structure to access a particular item.

MyFolderInfo(3).name
ans = 'myfile1.m'

Find Date File Last Modified

Get the date and time a file was last modified.

First, query the datenum field of the structure that dir returns. The value of the datenum field is a serial date number and does not vary with locale.

MyFileInfo = dir('myfile1.m');FileDate = MyFileInfo.datenum

As of R2022b, serial date numbers are not recommended. Convert the serial date number to a datetime value by using the datetime function.

FileDatetime = datetime(FileDate,ConvertFrom="datenum")
FileDatetime = datetime 24-May-2016 11:24:31

Input Arguments

collapse all

nameFile or folder name
character vector | string scalar

File or folder name, specified as a character vector or string scalar. If name is a string, enclose it in parentheses. For example, dir("FolderName").

To list files and folders at a remote location, name must contain a full path specified as a uniform resource locator (URL). For more information, see Work with Remote Data.

To search for multiple files, use wildcards in the file name. For example, dir *.txt lists all files with a txt extension in the current folder. To search through folders and subfolders on the path recursively, use wildcards in the path name. For example, dir */*.txt lists all files with a txt extension exactly one folder under the current folder, and dir **/*.txt lists all files with a txt extension zero or more folders under the current folder. Characters next to a ** wildcard must be file separators.

Note

MATLAB® always treats the * character as a wildcard, even on file systems that support * in file names.

The MATLAB dir function is consistent with the Microsoft® Windows® operating system dir command in that both support short file names generated by DOS.

Output Arguments

collapse all

listing — File attributes
structure array

File attributes, returned as a n-by-1 structurearray, where n is the number of files and foldersreturned by the dir command.

This table shows the fields in the structure.

Field Name

Description

Class

name

File or folder name

char

folder

Location of file or folder

char

date

Modification date timestamp

char

bytes

Size of the file in bytes

double

isdir

1 if name is a folder; 0 ifname is a file

logical

datenum

Modification date as serial date number.

double

Tips

  • 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 withan output argument and the results include a nonexistent file or afile that dir cannot query for some other reason.In this case, dir returns the following defaultvalues.

    date: '' bytes: [] isdir: 0 datenum: [] 

    Invalid entries most commonly occur on UNIX® platforms when dir queriesa symbolic link pointing to a nonexistent target. A nonexistent targetis 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.

Extended Capabilities

Version History

Introduced before R2006a

expand all

Starting in R2020a, on UNIX platforms, the wildcard expression *.* no longer matches folders or files without an extension. In previous releases, the expression matches folders or files regardless of extension, including files without an extension. This change of behavior does not apply to Microsoft Windows platforms.

See Also

cd | fileattrib | isfolder | ls | mkdir | rmdir | what

Topics

  • Specify File Names
  • Work with Remote Data

Commande MATLAB

Vous avez cliqué sur un lien qui correspond à cette commande MATLAB:

 

Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.

List folder contents - MATLAB dir- MathWorks France (1)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

List folder contents - MATLAB dir
- MathWorks France (2024)

References

Top Articles
YouTube to MP4 Converter | Online & Free MP4 Download
YouTube to MP4 Converter | Convert YouTube Video to MP4
Spasa Parish
Rentals for rent in Maastricht
159R Bus Schedule Pdf
Sallisaw Bin Store
Black Adam Showtimes Near Maya Cinemas Delano
Espn Transfer Portal Basketball
Pollen Levels Richmond
11 Best Sites Like The Chive For Funny Pictures and Memes
Things to do in Wichita Falls on weekends 12-15 September
Craigslist Pets Huntsville Alabama
Paulette Goddard | American Actress, Modern Times, Charlie Chaplin
Red Dead Redemption 2 Legendary Fish Locations Guide (“A Fisher of Fish”)
What's the Difference Between Halal and Haram Meat & Food?
R/Skinwalker
Rugged Gentleman Barber Shop Martinsburg Wv
Jennifer Lenzini Leaving Ktiv
Justified - Streams, Episodenguide und News zur Serie
Epay. Medstarhealth.org
Olde Kegg Bar & Grill Portage Menu
Cubilabras
Half Inning In Which The Home Team Bats Crossword
Amazing Lash Bay Colony
Juego Friv Poki
Dirt Devil Ud70181 Parts Diagram
Truist Bank Open Saturday
Water Leaks in Your Car When It Rains? Common Causes & Fixes
What’s Closing at Disney World? A Complete Guide
New from Simply So Good - Cherry Apricot Slab Pie
Drys Pharmacy
Ohio State Football Wiki
Find Words Containing Specific Letters | WordFinder®
FirstLight Power to Acquire Leading Canadian Renewable Operator and Developer Hydromega Services Inc. - FirstLight
Webmail.unt.edu
Tri-State Dog Racing Results
Navy Qrs Supervisor Answers
Trade Chart Dave Richard
Lincoln Financial Field Section 110
Free Stuff Craigslist Roanoke Va
Wi Dept Of Regulation & Licensing
Pick N Pull Near Me [Locator Map + Guide + FAQ]
Crystal Westbrooks Nipple
Ice Hockey Dboard
Über 60 Prozent Rabatt auf E-Bikes: Aldi reduziert sämtliche Pedelecs stark im Preis - nur noch für kurze Zeit
Wie blocke ich einen Bot aus Boardman/USA - sellerforum.de
Infinity Pool Showtimes Near Maya Cinemas Bakersfield
Dermpathdiagnostics Com Pay Invoice
How To Use Price Chopper Points At Quiktrip
Maria Butina Bikini
Busted Newspaper Zapata Tx
Latest Posts
Article information

Author: Moshe Kshlerin

Last Updated:

Views: 6364

Rating: 4.7 / 5 (57 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Moshe Kshlerin

Birthday: 1994-01-25

Address: Suite 609 315 Lupita Unions, Ronnieburgh, MI 62697

Phone: +2424755286529

Job: District Education Designer

Hobby: Yoga, Gunsmithing, Singing, 3D printing, Nordic skating, Soapmaking, Juggling

Introduction: My name is Moshe Kshlerin, I am a gleaming, attractive, outstanding, pleasant, delightful, outstanding, famous person who loves writing and wants to share my knowledge and understanding with you.