주요 콘텐츠

moveFile

R2026b

Move files in or out of project

Since R2026b

Description

entries = moveFile(proj,source,destination) moves the files or folders specified in the source argument into the destination specified in the destination argument. The destination must not contain an existing file or folder with the same name as the source. If a name conflict occurs, the function throws an error. You can move items within a project, into a project, or out of a project. The function allows you to move or rename files or folders depending on the values of the source and destination arguments:

  • To move a folder inside another folder, specify both the source and destination arguments as folder paths. The destination folder must exist. If the destination folder does not exist, the function renames the source folder instead. If the destination folder does not exist and is outside the root folder of the project, the function moves the source folder to the specified destination and renames it.

  • To move a file inside a folder, specify the source argument as a file and the destination argument as a folder. If the destination folder does not exist, the function renames the source file instead. If the destination folder does not exist and is outside the source folder location, the function moves the source file to that location and renames it.

The moveFile function updates the source control status and the project definition files impacted by the move.

example

entries = moveFile(proj,source,destination,Name=Value) specifies additional options as one or more name-value arguments.

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 folder.

 newfolder = fullfile(proj.RootFolder,"newfolder");
 mkdir(newfolder);

Move the editTimesTable.m and runTheseTests.m files from the utilities folder to the new folder.

moveFile(proj,["utilities/editTimesTable.m","utilities/runTheseTests.m"],"newfolder/")

Move the utilities folder and its remaining file into the new folder.

moveFile(proj,"utilities/","newfolder/")

Input Arguments

collapse all

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

Files or folders to move, specified as a cell array of character vectors, a string array, or a ProjectFile object array. Specify source as absolute file paths or paths relative to the project root folder.

File or folder destination, specified as a character vector or string scalar. Specify destination as absolute file paths or paths relative to the project root folder.

Name-Value Arguments

collapse all

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: moveFile(proj,"myFile.m","myFolder/",IncludeReferences=true)

Option to include referenced projects when moving or renaming items, specified as a numeric or logical 1 (true) or 0 (false).

Data Types: logical

Option to update the items affected by the moving or renaming, specified as a numeric or logical 1 (true) or 0 (false).

Note

When you specify UpdateImpacted as true, the moveFile function detects references to the renamed model in MATLAB® files, including string literals such as sim('modelname'). However, the function does not modify these strings. As a result, the corresponding entries in the output table have Updated=false.

You must update these references manually.

Data Types: logical

Output Arguments

collapse all

Dependencies affected by the moving or renaming, returned as a table. If you set the UpdateImpacted argument to false, the function returns an empty table.

Version History

Introduced in R2026b