PowerShell的Get-ChildItem cmdlet返回的“模式”值有哪些?

时间:2011-02-08 23:41:55

标签: powershell

当我在目录(或任何返回文件系统项的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

我搜索并搜索了Google和我的本地PowerShell书籍,但我找不到有关Mode列含义的任何文档。

“模式”列的可能值是什么,每个值的含义是什么?

4 个答案:

答案 0 :(得分:50)

请注意,您看到的模式只是隐藏在enum属性中的位域Attributes的字符串表示形式。你可以通过简单地并排显示来确定单个字母的含义:

PS> gci|select mode,attributes -u

Mode                Attributes
----                ----------
d-----               Directory
d-r---     ReadOnly, Directory
d----l Directory, ReparsePoint
-a----                 Archive

无论如何,完整列表是:

d - Directory
a - Archive
r - Read-only
h - Hidden
s - System
l - Reparse point, symlink, etc.

答案 1 :(得分:7)

恕我直言,最具说明力的是代码本身:

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 + "-");

答案 2 :(得分:3)

这些是所有文件属性名称,可以找到here的含义:

PS C:\> [enum]::GetNames("system.io.fileattributes")
ReadOnly
Hidden
System
Directory
Archive
Device
Normal
Temporary
SparseFile
ReparsePoint
Compressed
Offline
NotContentIndexed
Encrypted

答案 3 :(得分:0)

调用这些“属性”是一个特定于Windows的名称,并打破了* nix调用此“模式”的传统。即man chmod表示“更改模式”。

看起来Windows API设计正在弯曲(或默许)更广泛行业中更受欢迎的术语:“模式”

+1来自我。