Get-ChildItem
Gets the items and child items in one or more specified locations.
语法
Items (默认值)
Get-ChildItem
[[-Path] <string[]>]
[[-Filter] <string>]
[-Include <string[]>]
[-Exclude <string[]>]
[-Recurse]
[-Depth <uint32>]
[-Force]
[-Name]
[-UseTransaction]
[-Attributes <FlagsExpression[FileAttributes]>]
[-Directory]
[-File]
[-Hidden]
[-ReadOnly]
[-System]
[<CommonParameters>]
LiteralItems
Get-ChildItem
[[-Filter] <string>]
-LiteralPath <string[]>
[-Include <string[]>]
[-Exclude <string[]>]
[-Recurse]
[-Depth <uint32>]
[-Force]
[-Name]
[-UseTransaction]
[-Attributes <FlagsExpression[FileAttributes]>]
[-Directory]
[-File]
[-Hidden]
[-ReadOnly]
[-System]
[<CommonParameters>]
说明
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.
Get-ChildItem
does not display empty directories. When a Get-ChildItem
command includes the
Depth or Recurse parameters, empty directories are not included in the output.
Locations are exposed to Get-ChildItem
by PowerShell providers. A location can be a file system
directory, registry hive, or a certificate store. For more information, see about_Providers.
参数
-Attributes
Gets files and folders with the specified attributes. This parameter supports all attributes and lets you specify complex combinations of attributes.
For example, to get non-system files (not directories) that are encrypted or compressed, type:
Get-ChildItem -Attributes !Directory+!System+Encrypted, !Directory+!System+Compressed
To find files and folders with commonly used attributes, use the Attributes parameter. Or, the parameters Directory, File, Hidden, ReadOnly, and System.
The Attributes parameter supports the following properties:
- Archive
- Compressed
- Device
- Directory
- Encrypted
- Hidden
- IntegrityStream
- Normal
- NoScrubData
- NotContentIndexed
- Offline
- ReadOnly
- ReparsePoint
- SparseFile
- System
- Temporary
For a description of these attributes, see the FileAttributes Enumeration.
To combine attributes, use the following operators:
!
(NOT)+
(AND),
(OR)
Do not use spaces between an operator and its attribute. Spaces are accepted after commas.
For common attributes, use the following abbreviations:
D
(Directory)H
(Hidden)R
(Read-only)S
(System)
参数属性
类型: | |
默认值: | None |
接受的值: | Archive, Compressed, Device, Directory, Encrypted, Hidden, IntegrityStream, Normal, NoScrubData, NotContentIndexed, Offline, ReadOnly, ReparsePoint, SparseFile, System, Temporary |
支持通配符: | False |
不显示: | False |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-Depth
This parameter was added in PowerShell 5.0 and enables you to control the depth of recursion. By
default, Get-ChildItem
displays the contents of the parent directory. The Depth parameter
determines the number of subdirectory levels that are included in the recursion and displays the
contents.
For example, Depth 2
includes the Path parameter's directory, first level of subdirectories,
and second level of subdirectories. By default directory names and file names are included in the
output.
Note
On a Windows computer from PowerShell or cmd.exe, you can display a graphical view of a directory structure with the tree.com command.
参数属性
类型: | UInt32 |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-Directory
To get a list of directories, use the Directory parameter or the Attributes parameter with the Directory property. You can use the Recurse parameter with Directory.
参数属性
类型: | SwitchParameter |
默认值: | None |
支持通配符: | False |
不显示: | False |
别名: | ad, d |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-Exclude
Specifies, as a string array, a property or property that this cmdlet excludes from the operation.
The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such
as *.txt
or A*
. Wildcard characters are accepted.
A trailing asterisk (*
) in the Path parameter is optional. For example, -Path C:\Test\Logs
or -Path C:\Test\Logs\*
. If a trailing asterisk (*
) is included, the command recurses into the
Path parameter's subdirectories. Without the asterisk (*
), the contents of the Path
parameter are displayed. More details are included in Example 5 and the Notes section.
参数属性
类型: | String[] |
默认值: | None |
支持通配符: | True |
不显示: | False |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-File
To get a list of files, use the File parameter. You can use the Recurse parameter with File.
参数属性
类型: | SwitchParameter |
默认值: | None |
支持通配符: | False |
不显示: | False |
别名: | af |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-Filter
Specifies a filter to qualify the Path parameter. The FileSystem
provider is the only installed PowerShell provider that supports the use of filters. Filters are
more efficient than other parameters, because the provider applies them when the cmdlet gets the
objects rather than having PowerShell filter the objects after they are retrieved. The filter string
is passed to the .NET API to enumerate files. That API only supports *
and ?
wildcards.
参数属性
类型: | String |
默认值: | None |
支持通配符: | True |
不显示: | False |
参数集
(All)
Position: | 1 |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-Force
Allows the cmdlet to get items that cannot otherwise not be accessed by the user, such as hidden or system files. The Force parameter does not override security restrictions. Implementation varies among providers. For more information, see about_Providers.
参数属性
类型: | SwitchParameter |
默认值: | False |
支持通配符: | False |
不显示: | False |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-Hidden
To get only hidden items, use the Hidden parameter or the Attributes parameter with the
Hidden property. By default, Get-ChildItem
does not display hidden items. Use the Force
parameter to get hidden items.
参数属性
类型: | SwitchParameter |
默认值: | None |
支持通配符: | False |
不显示: | False |
别名: | ah, h |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-Include
Specifies, as a string array, an item or items that this cmdlet includes in the operation. The value
of this parameter qualifies the Path parameter. Enter a path element or pattern, such as
"*.txt"
. Wildcard characters are permitted. The Include parameter is effective only when the
command includes the contents of an item, such as C:\Windows\*
, where the wildcard character
specifies the contents of the C:\Windows
directory.
参数属性
类型: | String[] |
默认值: | None |
支持通配符: | True |
不显示: | False |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-LiteralPath
Specifies a path to one or more locations. The value of LiteralPath is used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell PowerShell not to interpret any characters as escape sequences.
For more information, see about_Quoting_Rules.
参数属性
类型: | String[] |
默认值: | None |
支持通配符: | False |
不显示: | False |
别名: | PSPath |
参数集
LiteralItems
Position: | Named |
必需: | True |
来自管道的值: | False |
来自管道的值(按属性名称): | True |
来自剩余参数的值: | False |
-Name
Gets only the names of the items in the location. The output is a string object that can be sent down the pipeline to other commands. Wildcards are permitted.
参数属性
类型: | SwitchParameter |
默认值: | None |
支持通配符: | True |
不显示: | False |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-Path
Specifies a path to one or more locations. Wildcards are accepted. The default location is the
current directory (.
).
参数属性
类型: | String[] |
默认值: | Current directory |
支持通配符: | True |
不显示: | False |
参数集
Items
Position: | 0 |
必需: | False |
来自管道的值: | True |
来自管道的值(按属性名称): | True |
来自剩余参数的值: | False |
-ReadOnly
To get only read-only items, use the ReadOnly parameter or the Attributes parameter ReadOnly property.
参数属性
类型: | SwitchParameter |
默认值: | None |
支持通配符: | False |
不显示: | False |
别名: | ar |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-Recurse
Gets the items in the specified locations and in all child items of the locations.
参数属性
类型: | SwitchParameter |
默认值: | False |
支持通配符: | False |
不显示: | False |
别名: | s |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-System
Gets only system files and directories. To get only system files and folders, use the System parameter or Attributes parameter System property.
参数属性
类型: | SwitchParameter |
默认值: | None |
支持通配符: | False |
不显示: | False |
别名: | as |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-UseTransaction
Includes the command in the active transaction. This parameter is valid only when a transaction is in progress. For more information, see about_Transactions.
参数属性
类型: | SwitchParameter |
默认值: | False |
支持通配符: | False |
不显示: | False |
别名: | usetx |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
输入
String
You can pipe a string that contains a path to Get-ChildItem
.
输出
Object
The type of object that Get-ChildItem
returns is determined by the objects in the provider drive path.
String
If you use the Name parameter, Get-ChildItem
returns the object names as strings.
备注
- You can refer to
Get-ChildItem
by its built-in aliases,ls
,dir
, andgci
. For more information, see about_Aliases. Get-ChildItem
does not get hidden items by default. To get hidden items, use the Force parameter.- The
Get-ChildItem
cmdlet is designed to work with the data exposed by any provider. To list the providers available in your session, typeGet-PSProvider
. For more information, see about_Providers.