Main Content

addFolderIncludingChildFiles

Add folder and child files to project

Description

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.

example

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

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;

Create a new parent folder in the project folder.

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

Create a new subfolder in the parent folder.

newSubFolderPath = fullfile(newFolderPath, "newSubFolder");
mkdir(newSubFolderPath);

Create a new file in the subfolder.

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

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);
findFile(proj,"newFolder/newSubFolder/newVariables.mat")
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