我正在扫描文件夹中的文件,我需要以任何方式获取当前用户的每个文件的权限以表示为字符串。因此,对于附加文件的属性,我想表示类似fmrw 字符串的内容。
我试图在我的扫描循环中完成这个,但是得到空字符串。你能暗示我应该从这里去哪里还是选择另一种方法?提前致谢!
string permissionShort = string.Empty;
DirectorySecurity dSecurity = Directory.GetAccessControl(_directory.FullName);
foreach (FileSystemAccessRule rule in dSecurity.GetAccessRules(true, true, typeof(NTAccount)))
{
if (rule.FileSystemRights == FileSystemRights.Write)
permissionShort = permissionShort + "x";
if (rule.FileSystemRights == FileSystemRights.Read)
permissionShort = permissionShort + "x";
if (rule.FileSystemRights == FileSystemRights.AppendData)
permissionShort = permissionShort + "x";
if (rule.FileSystemRights == FileSystemRights.Modify)
permissionShort = permissionShort + "x";
if (rule.FileSystemRights == FileSystemRights.ExecuteFile)
permissionShort = permissionShort + "x";
}