Skip to content

Commit

Permalink
add get_permissions()
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Sep 16, 2024
1 parent b2c19d3 commit 9dd3dfe
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions +stdlib/get_permissions.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
function p = get_permissions(f)
arguments
f (1,1) string
end

p = string.empty;

% Get the permissions of a file or directory
[status, v] = fileattrib(f);
if status == 0
return
end

% Extract the permission string
p = "---------"; % Default permissions
if v.UserRead
p = replaceBetween(p, 1, 1, "r");
end
if v.UserWrite
p = replaceBetween(p, 2, 2, "w");
end
if v.UserExecute
p = replaceBetween(p, 3, 3, "x");
end
if v.GroupRead
p = replaceBetween(p, 4, 4, "r");
end
if v.GroupWrite
p = replaceBetween(p, 5, 5, "w");
end
if v.GroupExecute
p = replaceBetween(p, 6, 6, "x");
end
if v.OtherRead
p = replaceBetween(p, 7, 7, "r");
end
if v.OtherWrite
p = replaceBetween(p, 8, 8, "w");
end
if v.OtherExecute
p = replaceBetween(p, 9, 9, "x");
end

end

0 comments on commit 9dd3dfe

Please sign in to comment.