When I run PowerShell's Get-ChildItem on a directory (or any cmdlet that returns file system items), it shows a column called Mode
, like this:
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
I searched and searched Google and my local PowerShell book, but I could not find any documentation on the meaning of the Mode
column.
What are the possible values of the Mode column and what does each one mean?
Get-ChildItem displays the files and directories in the PowerShell console. By default, Get-ChildItem lists the mode (Attributes), LastWriteTime, file size (Length), and the Name of the item. The letters in the Mode property can be interpreted as follows: l (link)
Description. The Get-ChildItem cmdlet gets the items in one or more specified locations. If the item is a container, it gets the items inside the container, known as child items. You can use the Recurse parameter to get items in all child containers and use the Depth parameter to limit the number of levels to recurse.
Note that the mode you see is just a string representation of a bitfield enum
that hides in the Attributes
property. You can figure out what the individual letters mean by simply showing both side by side:
PS> gci|select mode,attributes -u Mode Attributes ---- ---------- d----- Directory d-r--- ReadOnly, Directory d----l Directory, ReparsePoint -a---- Archive
In any case, the full list is:
d - Directory a - Archive r - Read-only h - Hidden s - System l - Reparse point, symlink, etc.
IMHO, the most explanatory is the code itself:
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 + "-");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With