Main Content

findFile

Find single project file by name

Starting in R2024a, use findFiles instead of findFile for more flexible solutions. findFiles offers advanced search capabilities that include finding files by label, category, and more.

Description

file = findFile(proj,fileOrFolder) gets the file in the specified project with the specified name. You need to get a file before you can query labels, or use the addLabel or removeLabel function.

example

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;

Use findFile to get a file by name. If the file is in a subfolder of the project root, you need to specify the full path.

myfile = findFile(proj,"source/timesTableGame.m")
myfile = 

  ProjectFile with properties:

                   Path: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m"
                 Labels: [1×1 matlab.project.Label]
               Revision: "734fbb2f815848e22694d9ac7ea28953d5e42635"
    SourceControlStatus: Unmodified

Alternatively, you can get files by index. Get the first file.

file = proj.Files(1);

Find out what you can do with the file.

methods(file)
Methods for class matlab.project.ProjectFile:

addLabel     findLabel    removeLabel         

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 file or folder to find, relative to the project root folder, specified as a character vector or string scalar. The specified value must include the full path from the project root to the file, including the names of any subfolders along the way. It must also include the file extension. The file or folder must be within the root folder.

Output Arguments

collapse all

Project file, returned as a ProjectFile object that you can query or modify.

Version History

Introduced in R2019a