Main Content


Add folder and child files to project



addFolderIncludingChildFiles(proj,folder) adds to the specified project a folder and all of its subfolders and files. To add only the specified folder without any of its subfolders and files, use addFile instead.

newfile = addFolderIncludingChildFiles(proj,folder) returns a ProjectFile object for the added file.


collapse all

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

proj = currentProject;

Create a new parent folder in the project folder.

newFolderPath = fullfile(proj.RootFolder, "newFolder");

Create a new subfolder in the parent folder.

newSubFolderPath = fullfile(newFolderPath, "newSubFolder");

Create a new file in the subfolder.

filepath = fullfile(newSubFolderPath, "newVariables.mat");

Add the parent folder and its subfolders and files to the project. Check to make sure the file in the subfolder was correctly added.

projectFile = addFolderIncludingChildFiles(proj, newFolderPath);
ans = 

  ProjectFile with properties:

               Path: "C:\myProjects\examples\TimesTableApp\newFolder\newSubFolder\newVariables.mat"
             Labels: [1×1 matlab.project.Label]
           Revision: ""
    SourceControlStatus: Added

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 folder to add to the project, specified as a character vector or string scalar. Specify a path relative to the project root folder. The specified folder must be within the project root folder.

Version History

Introduced in R2019a