次の方法で共有


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)

パラメーターのプロパティ

型:

FlagsExpression<T>[FileAttributes]

規定値:None
指定可能な値:Archive, Compressed, Device, Directory, Encrypted, Hidden, IntegrityStream, Normal, NoScrubData, NotContentIndexed, Offline, ReadOnly, ReparsePoint, SparseFile, System, Temporary
ワイルドカードのサポート:False
DontShow:False

パラメーター セット

(All)
配置: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
DontShow:False

パラメーター セット

(All)
配置: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
DontShow:False
Aliases:ad, d

パラメーター セット

(All)
配置: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
DontShow:False

パラメーター セット

(All)
配置: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
DontShow:False
Aliases:af

パラメーター セット

(All)
配置: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
DontShow:False

パラメーター セット

(All)
配置: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
DontShow:False

パラメーター セット

(All)
配置: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
DontShow:False
Aliases:ah, h

パラメーター セット

(All)
配置: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
DontShow:False

パラメーター セット

(All)
配置: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
DontShow:False
Aliases:PSPath

パラメーター セット

LiteralItems
配置: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
DontShow:False

パラメーター セット

(All)
配置: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
DontShow:False

パラメーター セット

Items
配置: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
DontShow:False
Aliases:ar

パラメーター セット

(All)
配置:Named
必須:False
パイプラインからの値:False
プロパティ名別のパイプラインからの値:False
残りの引数からの値:False

-Recurse

Gets the items in the specified locations and in all child items of the locations.

パラメーターのプロパティ

型:SwitchParameter
規定値:False
ワイルドカードのサポート:False
DontShow:False
Aliases:s

パラメーター セット

(All)
配置: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
DontShow:False
Aliases:as

パラメーター セット

(All)
配置: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
DontShow:False
Aliases:usetx

パラメーター セット

(All)
配置: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, and gci. 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, type Get-PSProvider. For more information, see about_Providers.