Main Content



Return paths of file collection

Since R2023a



p = paths(fc) returns the paths to the files and folders in the specified file collection as a string row vector.

You can use file collections to specify task inputs and outputs. For more information about task inputs and outputs, see Improve Performance with Incremental Builds.

Input Arguments

expand all

File collection, specified as a array.



To learn about attributes of methods, see Method Attributes.


expand all

Create file collections and return their paths.

Import the FileCollection class.


Create the folder structure used in this example. See the code of the local function createFile, which is used to create the files, at the end of this example.

mkdir source
mkdir source private

Create a file collection from all the .m files in the source folder and any of its subfolders. In this example, fc1 is a object because it is defined by a pattern that includes the * and ** wildcards.

fc1 = FileCollection.fromPaths("source/**/*.m")
fc1 = Glob

Return the paths of the file collection. When you call paths on a Glob object, the method returns the paths to the files and folders on disk that match the Glob pattern.

ans = 4×1 string

Add a file to the source folder, and return the paths of the file collection again. Even though fc1 has not been modified, the file collection has an additional path because its pattern now matches the newly created file as well.

ans = 5×1 string

Now, create file collections from the .m files in the source folder and any of its subfolders, as well as from another folder named nonexistentFolder. The fromPaths static method returns fc2 as a 1-by-2 FileCollection vector. The first element of the vector is a Glob object. The second element is a object because it represents a single folder.

fc2 = FileCollection.fromPaths(["source/**/*.m" "nonexistentFolder"])
fc2 = 1×2 heterogeneous FileCollection (Glob, File) array with no properties.
     source/**/*.m      nonexistentFolder 

Return the paths of fc2. In this example, even though nonexistentFolder does not exist on disk, the paths method returns the path to it. The method searches for files and folders on disk only for patterns that include the * or ** wildcard. If you call paths on a File object, the method returns the path to the specified file or folder even if it does not exist on disk.

ans = 6×1 string

Local Function

This code shows the local function used in this example.

function createFile(filename)

Version History

Introduced in R2023a