MATLAB Answers

fileattrib is returning the wrong (incorrect) results

조회 수: 7(최근 30일)
Matt
Matt 2015년 7월 17일
댓글: Matt 2015년 7월 17일
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.

채택된 답변

Walter Roberson
Walter Roberson 2015년 7월 17일
You are not the owner of the directory. UserWrite is the write permission that the owner of the directory would have.
  댓글 수: 3
Matt
Matt 2015년 7월 17일
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.

댓글을 달려면 로그인하십시오.

추가 답변(0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by