Main Content


Class: matlab.buildtool.Plan
Package: matlab.buildtool

Create file collections

Since R2023a



fc = files(plan,p) creates file collections from the specified paths p and returns the file collections as a array the same size as p. If p contains relative paths, the method uses the root folder of plan to convert them to absolute paths.

Input Arguments

expand all

Plan, specified as a matlab.buildtool.Plan object.

Paths to files and folders, specified as a string array, character vector, or cell array of character vectors. The paths can include the * and ** wildcards:

  • The * wildcard can appear in both filenames and pathnames. It matches any number of characters, including zero characters.

  • The ** wildcard can appear in pathnames, but not in filenames. Characters next to a ** wildcard must be file separators. ** matches any number of characters, including zero characters. You can use this wildcard to represent subfolders of a specified folder recursively.

When you specify a path using wildcards, the path does not match any files or folders that start with a dot (.) unless the path itself starts with a dot. In addition, a path that ends with a file separator matches only folders.

Example: "src" represents the file or folder named src.

Example: "src/*.m" matches all the .m files in the src folder.

Example: "src/**/*.m" matches all the .m files in the src folder and any of its subfolders.


expand all

Specify the inputs of a task by using the files method. Tasks with specified inputs or outputs support incremental builds.

Open the example and then navigate to the files_plan_example folder, which contains a build file.

cd files_plan_example

This code shows the contents of the build file. The main function of the build file calls the files method to create a FileCollection object from the specified path.

function plan = buildfile
% Create a plan from the task function
plan = buildplan(localfunctions);

% Specify the inputs and outputs of the "pcode" task
plan("pcode").Inputs = files(plan,"source/**/*.m");
plan("pcode").Outputs = plan("pcode").Inputs.replace(".m",".p");

function pcodeTask(context)
% Create P-code files
filePaths = context.Task.Inputs.paths;

Run the "pcode" task. The task obfuscates its inputs and creates the P-code files in the same folders as the inputs.

buildtool pcode
** Starting pcode
** Finished pcode

Run the task again. The build tool skips the task because none of the inputs or outputs of the task have changed since the last run.

buildtool pcode
** Skipped pcode: up-to-date

Add a file to the source folder, and then rerun the task. The build tool runs the task because the inputs of the task have changed between consecutive builds.

buildtool pcode
** Starting pcode
** Finished pcode

Version History

Introduced in R2023a

expand all