This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Determine whether input is a folder


result = isdir(folderName)



result = isdir(folderName) returns 1 if folderName is a folder. Otherwise, it returns 0.


collapse all

Check whether the input myfile1.m is a folder. A result of 0 indicates that myfile1.m is not a folder.

result = isdir('myfile1.m')
result = logical

Create the folder myfolder, then check whether myfolder is a folder. A result of 1 indicates that myfolder is a folder.

mkdir myfolder;
result = isdir('myfolder')
result = logical

Get the Current Folder listing and filter out only the folders.

Create two folders, myfolder1 and myfolder2.

mkdir myfolder1
mkdir myfolder2

Get the current folder listing.

listing = dir;

Filter out only the folders.

onlyFolders = listing([listing.isdir]);
ans = 
ans = 
ans = 
ans = 

Input Arguments

collapse all

Name of the folder, specified as a character vector. folderName can be specified as an absolute or relative path.

Output Arguments

collapse all

Indication of whether the specified name is a folder, specified as 0 or 1. If the specified name is a folder, result is 1. Otherwise, result is 0.

Data Types: logical

See Also


Introduced before R2006a

Was this topic helpful?