Main Content

mustBeSymbolicLink

R2026b

Validate that input is symbolic link

Since R2026b

    Description

    mustBeSymbolicLink(value) throws an error if value is not a symbolic link. This function does not return a value.

    mustBeSymbolicLink calls the isSymbolicLink function to determine if the input is a symbolic link.

    example

    Examples

    collapse all

    Use the mustBeSymbolicLink function to ensure that a path passed to a function is a symbolic link.

    The resolveLink function ensures that the input path is a symbolic link before resolving it.

    function target = resolveLink(path)
        arguments
            path {mustBeSymbolicLink}
        end
        target = resolveFilePath(path);
    end

    Passing a path that is not a symbolic link results in an error.

    target = resolveLink("C:\Users\myfile.txt")
    Error using resolveLink (line 3)
     target = resolveLink("C:\Users\myfile.txt")
                          ^^^^^^^^^^^^^^^^^^^^^^
    Invalid argument at position 1. These symbolic links do not exist:
    'C:\Users\myfile.txt'.

    Use mustBeSymbolicLink as a property validator to ensure that a property value is a symbolic link.

    This class restricts the value of LinkPath to a symbolic link.

    classdef LinkFollower
       properties
          LinkPath {mustBeSymbolicLink}
       end
    end

    Create an object and assign a value to its property.

    obj = LinkFollower;
    obj.LinkPath = "C:\Users\regularFile.txt";
    Error using implicit default value of property 'LinkPath' of class 'LinkFollower'. Value must be 
    text with one or more characters.

    Input Arguments

    collapse all

    Value to validate, specified as a scalar or array of any MATLAB® type or class.

    Example: "myLink"

    Example: "C:\Work\myLink"

    Tips

    • mustBeSymbolicLink is designed to be used for property and function argument validation.

    Version History

    Introduced in R2026b