Main Content

matlab.project.isUnderProjectRoot

Determine whether file or folder is under project root folder

Since R2023a

    Description

    example

    tf = matlab.project.isUnderProjectRoot(fileOrFolder) returns 1 (true) if the input file or folder is under a project root folder and 0 (false) otherwise. matlab.project.isUnderProjectRoot returns 0 (false) if fileOrFolder is a project root folder.

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

    example

    [tf,projectRoot] = matlab.project.isUnderProjectRoot(fileOrFolder) returns the location of the first project root it finds. If the input file or folder is not under a project root, projectRoot is an empty string.

    Examples

    collapse all

    Determine whether a file is under a project root and return the path of the project root folder.

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

    Input Arguments

    collapse all

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

    If you specify a path to a file that does not exist, the function returns 0. The file is not under a project root folder.

    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 under a project root.

    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 R2023a