MATLAB: Fileattrib is returning the wrong (incorrect) results

MATLAB

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.

Best Answer

You are not the owner of the directory. UserWrite is the write permission that the owner of the directory would have.