Search files or folders that start with m but only in the folder users not in subfolders

To open a new Finder window without opening a specific folder, click the Finder icon

Search files or folders that start with m but only in the folder users not in subfolders
in the Dock, then choose File > New Finder Window or press Command-N.

Main Content

Syntax

Description

dir lists files and folders in the current folder.

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.

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 myfolder
movefile myfile1.m myfolder
movefile myfile2.m myfolder
movefile myfile3.m myfolder

List the files in 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 myfolder
movefile myfile1.m myfolder
movefile myfile2.m myfolder
movefile myfile3.txt myfolder

List the matching files in myfolder.

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.m
myfolder2
     myfile2.m
     myfolder3
         myfile3.m

mkdir myfolder1
mkdir myfolder1/myfolder2
mkdir myfolder1/myfolder2/myfolder3

movefile myfile1.m myfolder1
movefile myfile2.m myfolder1/myfolder2
movefile myfile3.m myfolder1/myfolder2/myfolder3

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

Files Found in Current Folder:

myfile1.m  

Files Found in: myfolder2

myfile2.m  

Files Found in: myfolder2\myfolder3

myfile3.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 myfolder
movefile myfile1.m myfolder
movefile myfile2.m myfolder
movefile 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.

Find Date File Last Modified

Get the serial date number for the date and time a file was last modified.

Use the datenum field of the structure returned by the dir command. Do not use the datenum function to convert the date field of the structure to a number. The results of the datenum function vary depending on the locale. Instead, use the datenum field.

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

Input Arguments

collapse all

name — File 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 structure array, where n is the number of files and folders returned 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 if name 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 with an output argument and the results include a nonexistent file or a file that dir cannot query for some other reason. In this case, dir returns the following default values.

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

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

    Or type

    MATLAB returns the results to the character array r.

Extended Capabilities

Thread-Based Environment Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.

This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.

Version History

Introduced before R2006a

expand all

R2020a: Wildcard expression *.* on UNIX platforms matches only files that have an extension

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.

How can I see what folders a user has access to?

Step 2 – Right-click the folder or file and click “Properties” in the context menu. Step 3 – Switch to “Security” tab and click “Advanced”. Step 4 – In the “Permissions” tab, you can see the permissions held by users over a particular file or folder. Step 5 – Click “Effective Access” tab.

How do I get a list of files in a directory and subfolders?

Open File Explorer in Windows. ... .
Click in the address bar and replace the file path by typing cmd then press Enter..
This should open a black and white command prompt displaying the above file path..
Type dir /A:D. ... .
There should now be a new text file called FolderList in the above directory..

What is a folder with subfolders called?

Directory: A named group of files (a folder); a directory that contains more folders (subdirectories) are called the "parent" and the folder within it is referred to as the "child" of that directory..

How do I search for a file in a subfolder?

To search for files in File Explorer, open File Explorer and use the search box to the right of the address bar. Tap or click to open File Explorer. Search looks in all folders and subfolders within the library or folder you're viewing.