Contenuto principale

resolveFilePath

R2026b

Get absolute path for file

Since R2026b

    Description

    absolutePath = resolveFilePath(name) returns the absolute path to the file or folder specified by name. The input can be a file or folder name, a relative path, or a location on the MATLAB® path. If the function does not find the specified file or folder, the output is a <missing> string.

    example

    absolutePath = resolveFilePath(name,Name=Value) specifies additional options using one or more name-value arguments. For example, specify EntryType="folder" to resolve paths to folders only.

    example

    Examples

    collapse all

    Get the absolute path to a sample file on the MATLAB path.

    absolutePath = resolveFilePath("peppers.png")
    absolutePath =
    
        "C:\Program Files\MATLAB\R2026b\toolbox\matlab\matlab_images\png\peppers.png"

    Resolve multiple file and folder names by passing a string array as input to the resolveFilePath function. The resulting string array of absolute paths is the same size as the input array.

    names = ["peppers.png";"myFolder";"nonExisting.ext"];
    absolutePaths = resolveFilePath(names)
    absolutePaths =
    
      3x1 string array
    
        "C:\Program Files\MATLAB\R2026b\toolbox\matlab\matlab_images\png\peppers.png"    
        "C:\Users\myUser\Projects\myFolder"    
        <missing>

    Resolve a name to a folder only, ignoring files with the same name.

    Specify EntryType="folder" to resolve the input to a folder only.

    absolutePath = resolveFilePath("results",EntryType="folder")
    absolutePath =
    
        "C:\Users\myUser\Projects\results"

    Resolve a symbolic link to its target location.

    Specify the ResolveSymbolicLinks name-value argument as true to get the absolute path to the target of a symbolic link.

    absolutePath = resolveFilePath("mySymbolicLink",ResolveSymbolicLinks=true)
    absolutePath =
    
        "C:\Users\myUser\Documents\Data\targetFile.mat"

    Input Arguments

    collapse all

    File or folder name to resolve, specified as a string array, character vector, or cell array of character vectors containing any of these values:

    • File or folder name — "peppers.png", "Documents"

    • Relative path, a path in terms of the current working directory — "../myFile.txt"

    • A location on the MATLAB path — "peppers.png", "matlab_images/png/peppers.png"

    • Absolute path — "C:\Users\myUser\file.txt"

    • URL for a remote resource — "s3://mybucket/data.csv"

    resolveFilePath resolves only files and folders that exist on disk, or in your file system. It does not resolve built-in functions, classes, or identifiers that include namespaces.

    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: resolveFilePath("results",EntryType="folder") resolves the input to a folder only, ignoring files with the same name.

    Type of file system entry to resolve, specified as one of these values:

    • "auto" — Look for a file first. If no file is found, look for a folder. Return <missing> if neither is found. If the input includes a broken symbolic link, specifying EntryType="auto" with ResolveSymbolicLinks=false results in the full path to the broken link.

    • "file" — Resolve only to files. Ignore folders with the same name.

    • "folder" — Resolve only to folders. Ignore files with the same name.

    Data Types: char | string

    Option to resolve symbolic links to their target locations, specified as a numeric or logical 0 (false) or 1 (true).

    If you specify ResolveSymbolicLinks as true, for symbolic links in the input, the function returns the absolute path of the target. By default, ResolveSymbolicLinks is false, and the function returns the absolute path of the symbolic link itself.

    If the input includes a broken symbolic link, specifying EntryType="auto" with ResolveSymbolicLink=false results in the full path to the broken link.

    Output Arguments

    collapse all

    Resolved absolute path, returned as a string scalar or string array. The output has the same dimensions as the input name.

    If the function does not find a file or folder specified by name, then the corresponding element in the output is a <missing> string.

    Tips

    • Several MATLAB functions provide different resource-lookup capabilities. Choose the function that matches the type of resource you want to find:

      • To resolve paths of files and folders that exist on disk, including relative paths that contain ./ or ../ segments, use resolveFilePath.

      • To find static methods, functions that include namespaces or built-in functions, use which.

      • To list files in a folder, namespace folder, or class folder, use what.

    • If a given input has multiple matches (for example, a file exists both in the current folder and on the MATLAB path), the function returns only the earliest match.

    • resolveFilePath searches the current folder first, followed by folders on the MATLAB path.

    Version History

    Introduced in R2026b