Main Content

matlab.unittest.constraints.IsFolder Class

Namespace: matlab.unittest.constraints
Superclasses: matlab.unittest.constraints.BooleanConstraint

Test if value is folder


The matlab.unittest.constraints.IsFolder class provides a constraint to test if a value represents a folder.




c = matlab.unittest.constraints.IsFolder creates a constraint to test if a value represents a folder. The constraint is satisfied by a string scalar or character vector that specifies the path to an existing folder. The value can be a relative path, but the relative path must be in the current folder. Otherwise, the value must be a full path.


collapse all

Test if a folder exists using the IsFolder constraint.

First, import the classes used in this example.

import matlab.unittest.TestCase
import matlab.unittest.constraints.IsFolder

Create a test case for interactive testing.

testCase = TestCase.forInteractiveUse;

Create the subfolder myFolder in your current folder if it does not exist. Then add a file to myFolder.

if ~isfolder("myFolder")
    mkdir myFolder
filename = "myFolder" + filesep + "myFile.dat";

Verify that myFolder exists in your current folder.

Verification passed.

Test if a file in myFolder satisfies the IsFolder constraint. The test fails because the constraint is satisfied only by a value that represents a folder.

Verification failed.
    Framework Diagnostic:
    IsFolder failed.
    --> Value does not point to an existing folder.
    --> Current folder during evaluation:
    Actual Value:

Delete the folder, and test if the folder no longer exists. The test passes.

rmdir myFolder s
Verification passed.

Version History

Introduced in R2018a