fileattrib

Reads the attributes of a file or folder.

Category: Programming > Files and Folders

Syntax

[status, attrs] = fileattrib(name)

Returns whether name was found and a struct of its attributes.

fileattrib(name)

Displays the attributes.

Description

The attribute struct has one field for each property of the item. Name holds the full path, directory is 1 for a folder, and the User... fields tell whether the current user can read, write or execute it.

Use the first output to test existence without raising an error: a name that does not exist gives a false status.

Input arguments

name
File or folder.

Output arguments

status
true if the item exists.
attrs
Struct with Name, archive, system, hidden, directory, and the permission fields UserRead, UserWrite, UserExecute, GroupRead and the like. On Windows the group and other fields are NaN.

Example

Attributes of a file and a folder

mkdir box
writelines('x', 'box/f.txt');
[ok, a] = fileattrib('box/f.txt');
ok
a.directory
a.UserRead
[~, b] = fileattrib('box');
b.directory
Output
ok = logical
   1
ans = logical
   0
ans = logical
   1
ans = logical
   1

Notes

MatLivre reads attributes; a mode string such as '+w' or '-w' is accepted but does not change them.

See also

dir isfile isfolder exist