Main Content

findFiles

Find project files by category or label name

Since R2024a

Description

example

projectFiles = findFiles(proj) lists all project files and folders in the project proj.

example

projectFiles = findFiles(proj,files) filters the files files and returns only the files that are project files.

example

projectFiles = findFiles(___,Name=Value) specifies additional options as one or more name-value arguments. Use this syntax to find files in a project using their label, to include referenced projects in the search, and more.

Examples

collapse all

Open the Times Table App project. Use currentProject to create a project object from the currently loaded project.

openExample("matlab/TimesTableProjectExample")
proj = currentProject;

List all files that are part of the project.

testFiles = findFiles(proj);

Open the Times Table App project. Use currentProject to create a project object from the currently loaded project.

openExample("matlab/TimesTableProjectExample")
proj = currentProject;

Create an array of the files you want to query.

fileInProject = fullfile("source","timestable.mlapp");
fileOutsideProject = fullfile("..","TimesTableProjectExample.m");
files = [fileInProject;fileOutsideProject]
files = 

  2×1 string array

    "source\timestable.mlapp"
    "..\TimesTableProjectExample.m"

Find which files are project files.

projectFiles = findFiles(proj,files)
files = 

  1×1 string array

    "C:\Users\username\Documents\TimesTableProjectExample\TimesTableApp\source\timestable.mlapp"
    

To query the project file properties such as source control status and revision ID, create a ProjectFile object instead.

projectFiles = findFiles(proj,files,OutputFormat="ProjectFile")
  ProjectFile with properties:

                   Path: "C:\Users\username\Documents\TimesTableProjectExample\TimesTableApp\source\timestable.mlapp"
               Revision: "00ef792a696a10b62db2b2951efbab4ecbae6610"
    SourceControlStatus: Unmodified
                 Labels: [1×1 matlab.project.Label]
    

Open the Times Table App project. Use currentProject to create a project object from the currently loaded project.

openExample("matlab/TimesTableProjectExample")
proj = currentProject;

Create a test suite from all project files labeled Test.

testFiles = findFiles(proj,Label="Test");

If the project has more than one category with the label Test, specify the category name. For example, testFiles = findFiles(proj,Category="Classification",Label="Test");

Open the top-level project in your hierarchy and create a project object.

proj = openProject('C:/projects/TopLevelProject');

Find all files labeled Design in your project hierarchy, including the referenced projects.

allDesignFiles = findFiles(proj,Label="Design",IncludeReferences=true);

Input Arguments

collapse all

Project, specified as a matlab.project.Project object. Use currentProject to create a project object from the currently loaded project.

Path of the files to filter, specified as a string array or a cell array of character vectors. When you specify files that include files outside of the project root folder or that are not part of the project, the function returns only the files that are project files.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: findFiles(proj,Label="Test",IncludeReferences=true,OutputFormat="ProjectFile")

Name of the category of labels, specified as a character vector or string scalar.

If you specify only the category name without the label name, the function returns all files that have labels from the specified category.

If you have more than one category in your project with same label names, specify both the category name and the label name.

Data Types: char | string

Name of the label, specified as a character vector or string scalar.

If you specify only the category name without the label name, the function returns all files that have labels from the specified category.

If you have more than one category in your project with same label names, specify both the category name and the label name.

Data Types: char | string

Option to include the referenced projects in the search, specified as a numeric or logical 1 (true) or 0 (false).

Data Types: logical

Option to choose the format of the output, specified as "string" or "ProjectFile". Use the "ProjectFile" format if you require information about the file such as the source control status and revision ID.

Output Arguments

collapse all

Project files, returned as a string array or a ProjectFile object, depending on the value you specify for OutputFormat.

Version History

Introduced in R2024a