addFolderIncludingChildFiles - Add folders and child files to project - MATLAB (original) (raw)

Add folders and child files to project

Syntax

Description

addFolderIncludingChildFiles([proj](#mw%5F22d67836-8c38-4e6c-9064-f55db1c623fa),[folders](#mw%5F7d30933f-a4ec-4def-af97-32082f278b69)) adds folders and all of their subfolders and files to the specified project. To add only the specified folders without any of their subfolders and files, use addFile instead.

example

newfiles = addFolderIncludingChildFiles([proj](#mw%5F22d67836-8c38-4e6c-9064-f55db1c623fa),[folders](#mw%5F7d30933f-a4ec-4def-af97-32082f278b69)) returns an array of ProjectFile objects for the added files.

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); fileDetails = findFiles(proj,"newFolder/newSubFolder/newVariables.mat",OutputFormat="ProjectFile")

fileDetails =

ProjectFile with properties:

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

Create an empty project.

proj = matlab.project.createProject(Name="MyProject",Folder="C:\work\myproject");

Create two new folders and subfolders in the project folder.

mkdir("ParentFolder1","ChildFolder1"); mkdir("ParentFolder2","ChildFolder2");

Create new files in the subfolders.

filepath1 = fullfile(fullfile("ParentFolder1","ChildFolder1"),"Variables1.mat"); filepath2 = fullfile(fullfile("ParentFolder2","ChildFolder2"),"Variables2.mat"); save(filepath1); save(filepath2);

Add all folders, subfolders, and files to the project

addFolderIncludingChildFiles(proj,proj.RootFolder);

Input Arguments

collapse all

Path of the folders to add to the project, specified as a string array or a cell array of character vectors. The folders must be under the project root folder.

If you use the project root folder, the function adds all folders, subfolders, and files under the project root to the project.

Version History

Introduced in R2019a

expand all

Starting in R2025a, the addFolderIncludingChildFiles function supports using the project root folder to add all folders, subfolders, and files to a project in one step. For more information, see Add All Folders and Files to Project.

Starting in R2025a, the addFolderIncludingChildFiles function supports adding multiple folders and files to a project at the same time.