Main Content

createSymbolicLink

Create symbolic link

Since R2024b

    Description

    createSymbolicLink(link,target) creates the symbolic link link to direct to the file, folder, or symbolic link at target. Symbolic links allow you to refer to data indirectly. The deletion of a symbolic link has no effect on the target file, folder, or symbolic link.

    On Windows® operating systems, you must start MATLAB® with the Run as administrator option to work with symbolic links. To start MATLAB with this option, right-click the MATLAB icon and select Run as administrator. If that option is not available, contact your system administrator.

    example

    createSymbolicLink(link,target,ReplacementRule=rule) specifies how to treat an existing symbolic link of the same name.

    Examples

    collapse all

    Create a file.

    str = "This is a sample file";
    writelines(str,"sample.txt");

    Create a symbolic link to the file.

    createSymbolicLink("newlink","sample.txt")

    Read from the file through the symbolic link.

    fid = fopen("newlink");
    out = fgets(fid)
    out =
     
        'This is a sample file
         '

    Input Arguments

    collapse all

    Symbolic link, specified as a string scalar or character vector.

    Target location, specified as a string scalar or character vector. You can specify an absolute or relative path to a file, folder, or another symbolic link.

    Example: "myfile.txt"

    Example: "C:\Work\MyFolder"

    Example: "mysymboliclink"

    Rule for existing symbolic links, specified as one of these values:

    • "preserve" – If a symbolic link with the same name exists, createSymbolicLink returns an error and does not create a new symbolic link.

    • "overwrite" – If a symbolic link with the same name exists and you have the required permissions to overwrite the existing symbolic link, createSymbolicLink overwrites the existing symbolic link with the new symbolic link. An error occurs if you do not have the required file or folder permissions.

    Version History

    Introduced in R2024b