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

    For large projects, checking whether a file is a project file can be a slow operation. Use matlab.project.isUnderProjectRoot to perform a quick check if 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 returns an empty string.

    Examples

    collapse all

    Determine if 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 character vector or string scalar.

    Example: "myfile.mlx"

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

    Output Arguments

    collapse all

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

    Version History

    Introduced in R2023a