Main Content


Determine whether file or folder belongs to project

Since R2023b



    tf = matlab.project.isFileInProject(fileOrFolder) returns 1 (true) if the specified file or folder specified by fileOrFolder belongs to a project folder and 0 (false) otherwise. If fileOrFolder is a project root folder, matlab.project.isFileInProject returns 0 (false).

    For large projects, checking whether a file is a project file can be a slow operation. For large projects, use the matlab.project.isUnderProjectRoot function to quickly check whether a file is under a project root.


    [tf,projectRoot] = matlab.project.isFileInProject(fileOrFolder) also returns the location of the project the function finds. If fileOrFolder does not belong to a project, then projectRoot is an empty string.


    collapse all

    Determine whether a file belongs to a project and return the path of the project root folder.

    filepath = "C:\workSpace\projectHierarchy\parentProject\referencedProject\scripts\myfile.mlx";
    [tf,projectRoot] = matlab.project.isFileInProject(filepath)
    tf =
    projectRoot = 

    Input Arguments

    collapse all

    Filename or filename path, specified as a string scalar, string array, or character vector.

    Example: "myfile.mlx"

    Example: "C:\workSpace\project\myfolder"

    Output Arguments

    collapse all

    True or false, returned as a 1 or 0. A value of 1 indicates that the file is a project file.

    Full path of the first project root folder that contains the file, returned as a string scalar, string array, or character vector.

    Version History

    Introduced in R2023b