GET_PERMISSIONS permissions of file or directory

output is char like 'rwxrwxr--'

Contents

inputs

Outputs

function [perm, b] = get_permissions(file)

try
  perm = perm2char(filePermissions(file));
  b = 'native';
catch e
  switch e.identifier
    case {'MATLAB:UndefinedFunction', 'Octave:undefined-function'}
      perm = perm2char(file_attributes(file));
      b = 'legacy';
    case 'MATLAB:io:filesystem:filePermissions:CannotFindLocation'
      perm = '';
      b = '';
    otherwise
      rethrow(e)
  end
end

end