Main Content

setPermissions

Set individual permissions

Since R2025a

Description

setPermissions(perms,propName,propVal) sets individual permissions of a file, folder, or symbolic link by setting properties of the specified permissions object.

example

setPermissions(perms,propName,propVal,Name=Value) specifies options using one or more name-value arguments. For example, set writable permissions for only the folders in the specified permissions array using setPermissions(perms,"Writable",true,PermissionsTarget=folders).

Examples

collapse all

Suppose that perms is a WindowsPermissions object that represents three files. Make the second file readable by setting its Readable property to true.

setPermissions(perms(2),"Readable",true);

You can also set the property value of a single file using dot notation.

perms(2).Readable = true;

Suppose that perms is a WindowsPermissions object that represents three files. Make all three files readable by setting the Readable property to true.

setPermissions(perms,"Readable",true);

Suppose that perms is a WindowsPermissions object that represents three files. Make all three files readable and writable by setting both the Readable and Writable properties to true.

setPermissions(perms,["Readable", "Writable"],true);

Now, set all three files to be readable, but not writable, by setting the Readable property to true and the Writable property to false.

setPermissions(perms,["Readable","Writable"],[true,false])

Input Arguments

collapse all

Permissions object, specified as a WindowsPermissions, UnixPermissions, or FileSystemEntryPermissions object. This function sets properties of the specified object.

Name of the property to set, specified as a string array, character vector, or cell array of character vectors.

Example: "Readable"

Example: ["GroupRead","OtherRead"]

Value for the property, specified as a logical scalar or array.

Example: true

Example: [true,false]

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: setpermissions(perms,prop,val,UseParallel=true) enables parallel processing.

Target to set permissions, specified as all, files, folders, symbolicLinks, or target. If the permissions input represents a folder, the possible values are all, files, folders, and symbolicLinks. If the permissions input represents a symbolic link, the only possible value is target, which specifies the target instead of the symbolic link.

Use parallel processing, specified as numeric or logical 0 (false) or 1 (true). Parallel processing can result in improved performance when setting permissions, especially with remote data (requires Parallel Computing Toolbox™).

Version History

Introduced in R2025a