fileattrib is returning the wrong (incorrect) results
Show older comments
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
More Answers (0)
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!