| Contents | Index |
fileattrib displays attribute values for the current folder, using the following structure, where Name is always a string containing the current folder name. For the other fields, a value of 0 indicates that the attribute is off, 1 indicates that the attribute is on, and NaN indicates that the attribute does not apply:
| Name |
| archive |
| system |
| hidden |
| directory |
| UserRead |
| UserWrite |
| UserExecute |
| GroupRead |
| GroupWrite |
| GroupExecute |
| OtherRead |
[status,message,messageid] = fileattrib(name,attribs,___) sets the specified file attributes and gets the status:
If status is 0, then message is the error message, and messageid is the error message identifier.
If status is 1, then message is a structure containing the attributes of the named file or folder, and messageid is an empty string.
View attributes of the current folder, assuming the current folder is C:\my_MATLAB_files.
fileattrib
ans =
Name: 'C:\my_MATLAB_files'
archive: 0
system: 0
hidden: 0
directory: 1
UserRead: 1
UserWrite: 1
UserExecute: 1
GroupRead: NaN
GroupWrite: NaN
GroupExecute: NaN
OtherRead: NaN
OtherWrite: NaN
OtherExecute: NaNThe attributes indicate that you have read, write, and execute permissions for the current folder.
View attributes of file collatz.m.
fileattrib('collatz.m')ans =
Name: 'C:\my_MATLAB_files\collatz.m'
archive: 1
system: 0
hidden: 0
directory: 0
UserRead: 1
UserWrite: 0
UserExecute: 1
GroupRead: NaN
GroupWrite: NaN
GroupExecute: NaN
OtherRead: NaN
OtherWrite: NaN
OtherExecute: NaNThe attributes indicate that the specfieid item is a file. You can read and execute the file, but cannot update it. The file is archived.
View attributes for the folder C:\my_MATLAB_files\doc.
fileattrib('C:\my_MATLAB_files\doc')ans =
Name: 'C:\my_MATLAB_files\doc'
archive: 0
system: 0
hidden: 0
directory: 1
UserRead: 1
UserWrite: 1
UserExecute: 1
GroupRead: NaN
GroupWrite: NaN
GroupExecute: NaN
OtherRead: NaN
OtherWrite: NaN
OtherExecute: NaNThe attributes indicate that you have read, write, and execute permissions for the specified folder.
View attributes for the folder /public on a UNIX system.
fileattrib('/public')ans =
Name: '/public'
archive: NaN
system: NaN
hidden: NaN
directory: 1
UserRead: 1
UserWrite: 1
UserExecute: 1
GroupRead: 1
GroupWrite: 0
GroupExecute: 1
OtherRead: 1
OtherWrite: 0
OtherExecute: 1The attributes indicate that you have read, write, and execute permissions for the specfied folder. In addition, users in your UNIX group and all others have read and execute permissions for the specified folder, but not write permissions.
Make myfile.m writeable.
fileattrib('myfile.m','+w')
Make the folder D:/work/results a read-only folder for all users on UNIX platforms.
fileattrib('D:/work/results','-w','a')
The minus (-) preceding the write attribute, w, removes the write status.
On Windows platforms, make the folder d:/work/results and all its contents read only and hidden.
fileattrib('D:/work/results','+h -w','','s')
Because a value for the users argument is not applicable on Windows systems, the argument is an empty string. The s argument applies the hidden and read-only attributes to the contents of the folder.
Get the attributes for the folder results and return them to a structure:
[stat,struc]=fileattrib('results')stat =
1
struc =
Name: 'D:\work\results'
archive: 0
system: 0
hidden: 0
directory: 1
UserRead: 1
UserWrite: 1
UserExecute: 1
GroupRead: NaN
GroupWrite: NaN
GroupExecute: NaN
OtherRead: NaN
OtherWrite: NaN
OtherExecute: NaNThe operation is successful as indicated by the status, stat, value of 1. The structure, struc, contains the file attributes.
Access the name attribute value in the structure. MATLAB returns the path for results.
struc.Name
ans = D:\work\results
Get the attributes for all files in the current folder with names that begin with new.
[stat,struc]=fileattrib('new*')stat =
1
mess =
1x3 struct array with fields:
Name
archive
system
hidden
directory
UserRead
UserWrite
UserExecute
GroupRead
GroupWrite
GroupExecute
OtherRead
OtherWrite
OtherExecuteThe results indicate there are three matching files.
View the file names.
struc.Name
ans = D:\work\results\newname.m ans = D:\work\results\newone.m ans = D:\work\results\newtest.m
View just the second file name.
struct(2).Name
ans = D:\work\results\newname.m
Show output that results when an attempt to set file attributes is successful.
[status, message, messageid] = fileattrib('C:/my_MATLAB_files\doc','+h -w','','s')
status =
1
message =
''
messageid =
''The status value of 1 indicates the set operation was successful; therefore, no error message or messageid is returned.
Show output that results when an attempt to set file attributes is unsuccessful.
[status, message, messageid] = fileattrib('C:/my_MATLAB_files\doc','+h w-','','s')
status =
0
message =
Illegal file mode characters on the current platform.
messageid =
MATLAB:FILEATTRIB:ModeSyntaxError
The status value of 0 indicates the set operation was unsuccessful. The minus sign incorrectly appears after w, instead of before it. The error message and messageid are returned.
status | Indication of whether attempt to set attribute was successful If attempt to set attribute was unsuccessful, status is 0. Otherwise, status is 1. | ||||||||||||||||||||||||||||||||||||||||||
message | Attribute structure or error message Attribute structure or error message, depending on whether you are setting or getting attributes and status.
When you are getting file attributes, the structure contains these fields and possible values.
| ||||||||||||||||||||||||||||||||||||||||||
messageid | Error message identifier Error message identifier returned when attempt to set attribute is unsuccessful (status is 0). If status is 1, messageid is an empty string. |
fileattrib is like the DOS attrib command, or the UNIX chmod command. [1]
cd | copyfile | delete | dir | ls | mkdir | movefile | rmdir
[1] UNIX is a registered trademark of The Open Group in the United States and other countries.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |