当我在目录(或任何返回文件系统项的cmdlet)上运行PowerShell的Get-ChildItem时,它会显示一个名为的列Mode,如下所示:
Directory: C:\MyDirectory
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 2/8/2011 10:55 AM Directory1
d---- 2/8/2011 10:54 AM Directory2
d---- 2/8/2011 10:54 AM Directory3
-ar-- 2/8/2011 10:54 AM 454 File1.txt
-ar-- 2/8/2011 10:54 AM 4342 File2.txt
Run Code Online (Sandbox Code Playgroud)
我搜索并搜索了Google和我当地的PowerShell书籍,但我找不到任何有关该Mode列含义的文档.
Mode列的可能值是什么,每个值是什么意思?
Joe*_*oey 54
请注意,您看到的模式只是enum隐藏在Attributes属性中的位域的字符串表示形式.您可以通过简单地并排显示来确定单个字母的含义:
PS> gci|select mode,attributes -u
Mode Attributes
---- ----------
d----- Directory
d-r--- ReadOnly, Directory
d----l Directory, ReparsePoint
-a---- Archive
Run Code Online (Sandbox Code Playgroud)
无论如何,完整列表是:
d - Directory
a - Archive
r - Read-only
h - Hidden
s - System
l - Reparse point, symlink, etc.
Run Code Online (Sandbox Code Playgroud)
恕我直言,最解释的是代码本身:
if (instance == null)
{
return string.Empty;
}
FileSystemInfo baseObject = (FileSystemInfo) instance.BaseObject;
if (baseObject == null)
{
return string.Empty;
}
string str = "";
if ((baseObject.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
{
str = str + "d";
}
else
{
str = str + "-";
}
if ((baseObject.Attributes & FileAttributes.Archive) == FileAttributes.Archive)
{
str = str + "a";
}
else
{
str = str + "-";
}
if ((baseObject.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
{
str = str + "r";
}
else
{
str = str + "-";
}
if ((baseObject.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
{
str = str + "h";
}
else
{
str = str + "-";
}
if ((baseObject.Attributes & FileAttributes.System) == FileAttributes.System)
{
return (str + "s");
}
return (str + "-");
Run Code Online (Sandbox Code Playgroud)
这些是所有文件属性名称,可以在此处找到含义:
PS C:\> [enum]::GetNames("system.io.fileattributes")
ReadOnly
Hidden
System
Directory
Archive
Device
Normal
Temporary
SparseFile
ReparsePoint
Compressed
Offline
NotContentIndexed
Encrypted
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
46671 次 |
| 最近记录: |