MATLAB Answers

fileattrib is returning the wrong (incorrect) results

8 views (last 30 days)
Matt
Matt on 17 Jul 2015
Commented: Matt on 17 Jul 2015
I have a GUI that asks the user via uigetdir for the location for some output files. As a check I want to be sure the user can write to that location. Here is the code
dn = uigetdir;
if ~(isequal(dn, 0))
if (dn(end) ~= filesep)
dn(end + 1) = filesep;
end
% check for writable directory
[~,fa,~] = fileattrib(dn);
if (fa.UserWrite == 1)
set(th, 'String', dn);
btn = findobj('tag','exec');
set(btn, 'Enable','on');
else
errordlg(sprintf('Directory: %s is not writable.', dn), ...
'Read Only')
end
Here is the result of that section for a directory that I do not have write permission.
fa =
Name: '*************************************'
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: NaN
According to the documentation I have write permission. I in fact do not. If I try to write a file I get a windows error stating as much. I can confirm I don't have permission through explorer. The documentation makes me think this should work on Windows...perhaps I missed something.

Accepted Answer

Walter Roberson
Walter Roberson on 17 Jul 2015
You are not the owner of the directory. UserWrite is the write permission that the owner of the directory would have.
  3 Comments
Matt
Matt on 17 Jul 2015
I found a function in the exchange that creates a directory and checks to see if the mkdir operation was successful. This solves the problem nicely. Thanks for looking into this Walter. I look forward to see what MathWorks says.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!