FileSystem の Get-ChildItem

適用対象: Windows PowerShell 2.0, Windows PowerShell 3.0, Windows PowerShell 4.0, Windows PowerShell 5.0

ファイル システム ドライブのファイルとフォルダーを取得します。

構文

Get-ChildItem [-Attributes <FileAttributes]>] [-Directory] [-File] [-Force] [-Hidden] [-ReadOnly] [-System] [-UseTransaction] [<CommonParameters>]

説明

ファイル システム ドライブで、Get-ChildItem コマンドレットはディレクトリ、サブディレクトリ、ファイルを取得します。ファイル システム ディレクトリで、サブディレクトリとファイルを取得します。

既定では、Get-ChildItem は非表示ではない項目を取得するが、Directory、File、Hidden、ReadOnly、System パラメーターを使用し、これらの属性を持つ項目のみを取得できます。複雑な属性検索を作成するには、Attributes パラメーターを使用します。これらのパラメーターを使用する場合、Get-ChildItem はパラメーターが AND 演算子で接続されているかのようにすべての検索条件を満たす項目のみを取得します。

注記:このカスタム コマンドレット ヘルプ ファイルは、ファイル システム ドライブにおける Get-ChildItem コマンドレットの動作について説明します。すべてのドライブにおける Get-ChildItem コマンドレットに関する詳細については、「Get-HelpGet-ChildItem -Path $null」と入力するか、「Get-ChildItem (https://go.microsoft.com/fwlink/?LinkID=113308)」をご覧ください。

パラメーター

-Attributes <FileAttributes]>

指定した属性のファイルとフォルダーを取得します。このパラメーターはすべての属性をサポートします。複雑な属性の組み合わせを指定できます。

たとえば、暗号化または圧縮されている非システム ファイル (非ディレクトリ) を取得するには、次のように入力します。

Get-ChildItem -Attributes !Directory+!System+Encrypted, !Directory+!System+Compressed

一般的に使用される属性を持つファイルとフォルダーを検索するには、Attributes パラメーターまたは Directory、File、Hidden、ReadOnly、System スイッチ パラメーターを使用できます。

Attributes パラメーターは次の属性をサポートします。Archive、Compressed、Device、Directory、Encrypted、Hidden、Normal、NotContentIndexed、Offline、ReadOnly、ReparsePoint、SparseFile、System、Temporary.これらの属性の説明については、「FileAttributes 列挙」を参照してください。URL は https://go.microsoft.com/fwlink/?LinkId=201508 です。

次の演算子を利用して属性を結合します。

! NOT

+ AND

, OR

演算子とその属性の間にはスペースを挿入できません。ただし、コンマの前にはスペースを挿入できます。

一般的に使用される属性には次の略語を使用できます。

D Directory

H Hidden

R Read-only

S System

必須?

false

位置は?

名前付き

既定値

パイプライン入力を許可する

false

ワイルドカード文字を許可する

false

-Directory

ディレクトリ (フォルダー) を取得します。

ディレクトリのみを取得するには、Directory パラメーターを使用し、File パラメーターを省略します。ディレクトリを除外するには、File パラメーターを使用して Directory パラメーターを省略するか、Attributes パラメーターを使用します。

ディレクトリを取得するには、Directory パラメーター、そのエイリアス「ad」、あるいは Attributes パラメーターの Directory 値を使用します。

必須?

false

位置は?

名前付き

既定値

None

パイプライン入力を許可する

false

ワイルドカード文字を許可する

false

-File

ファイルを取得します。

ファイルのみを取得するには、File パラメーターを使用し、Directory パラメーターを省略します。ファイルを除外するには、Directory パラメーターを使用して File パラメーターを省略するか、Attributes パラメーターを使用します。

ファイルを取得するには、File パラメーター、そのエイリアス「af」、あるいは Attributes パラメーターの File 値を使用します。

必須?

false

位置は?

名前付き

既定値

パイプライン入力を許可する

false

ワイルドカード文字を許可する

false

-Hidden

非表示のファイルとディレクトリ (フォルダー) のみを取得します。既定では、Get-ChildItem は非表示ではない項目のみを取得するが、Force パラメーターを使用すれば、結果に非表示の項目を含めることができます。

非表示の項目のみを取得するには、Hidden パラメーター、そのエイリアス「h」またはエイリアス「ah」、あるいは Attributes パラメーターの Hidden 値を使用します。非表示項目を除外するには、Hidden パラメーターを省略するか、Attributes パラメーターを使用します。

必須?

false

位置は?

名前付き

既定値

パイプライン入力を許可する

false

ワイルドカード文字を許可する

false

-ReadOnly

読み取り専用のファイルとディレクトリ (フォルダー) を取得します。

読み取り専用の項目を取得するには、ReadOnly パラメーター、そのエイリアス「ar」、あるいは Attributes パラメーターの ReadOnly 値を使用します。読み取り専用項目を除外するには、Attributes パラメーターを使用します。

必須?

false

位置は?

名前付き

既定値

パイプライン入力を許可する

false

ワイルドカード文字を許可する

false

-System

システムのファイルとディレクトリ (フォルダー) を取得します。

システムのファイルとフォルダーを取得するには、System パラメーター、そのエイリアス「as」、あるいは Attributes パラメーターの System 値を使用します。システムのファイルとフォルダーを除外するには、Attributes パラメーターを使用します。

必須?

false

位置は?

名前付き

既定値

パイプライン入力を許可する

false

ワイルドカード文字を許可する

false

-Force

非表示のファイルとフォルダーを取得します。既定では、非表示のファイルとフォルダーは除外されます。Hidden パラメーターまたは Attributes パラメーターの Hidden 値を使用すると、非表示のファイルとフォルダーも取得できます。

必須?

false

位置は?

名前付き

既定値

パイプライン入力を許可する

false

ワイルドカード文字を許可する

false

-UseTransaction

アクティブなトランザクションのコマンドが含まれます。このパラメーターは、トランザクションが進行中の場合のみ有効です。詳細については、「about_Transactions」を参照してください。

必須?

false

位置は?

名前付き

既定値

パイプライン入力を許可する

false

ワイルドカード文字を許可する

false

<CommonParameters>

このコマンドレットは次の共通パラメーターをサポートします。-Debug、-ErrorAction、-ErrorVariable、-OutBuffer、-OutVariable、-Verbose、-WarningAction、-WarningVariable。詳細については、「about_CommonParameters」を参照してください。

入力と出力

入力型は、コマンドレットにパイプできるオブジェクトの型です。戻り値の型は、コマンドレットによって返されるオブジェクトの型です。

入力

System.String[]

ファイル システム パス (引用符で括る) をパイプで Get-ChildItem に送ることができます。

出力

System.IO.DirectoryInfo、System.IO.FileInfo、System.String

Attributes、Directory、File、Hidden、ReadOnly、System パラメーターは Windows PowerShell 3.0 で導入され、

システム ドライブでのみ有効です。

Get-ChildItem エイリアス参照:

---------------------------------

Get-ChildItem dir

Directory d、ad

File af

Hidden h、ah

ReadOnly ar

System as

例 1

C:\PS>Get-ChildItem

Description
-----------
This command gets the files and subdirectories in the current directory. If the current directory does not have child items, the command does not return any results.





例 2

C:\PS>Get-Childitem -System -File -Recurse

Description
-----------
This command gets system files in the current directory and its subdirectories.





例 3

C:\PS>Get-ChildItem -Attributes !Directory,!Directory+Hidden

C:\PS> dir -att !d,!d+h

Description
-----------
These command get all files, including hidden files, in the current directory, but exclude subdirectories. The second command uses aliases and abbreviations, but has the same effect as the first.





例 4

C:\PS>dir -ad

Description
-----------
This command gets the subdirectories in the current directory. It uses the "dir" alias of the Get-ChildItem cmdlet and the "ad" alias of the Directory parameter.





例 5

C:\PS>Get-ChildItem -File -Attributes !ReadOnly -path C:\ps-test

Description
-----------
This command gets read-write files in the C:\ps-test directory.





例 6

C:\PS>get-childitem . -include *.txt -recurse -force

Description
-----------
This command gets all of the .txt files in the current directory and its subdirectories. 

The dot (.) represents the current directory. The Include parameter specifies the file name extension. The Recurse parameter directs Windows PowerShell to search for objects recursively, and it indicates that the subject of the command is the specified directory and its contents. The Force parameter adds hidden files to the display.





例 7

C:\PS>get-childitem c:\windows\logs\* -include *.txt -exclude A*

Description
-----------
This command gets the .txt files in the Logs subdirectory, except for those whose names start with the letter A. It uses the wildcard character (*) to indicate the contents of the Logs subdirectory, not the directory container. Because the command does not include the Recurse parameter, Get-ChildItem does not include the contents of the current directory automatically; you need to specify it.





例 8

C:\PS>get-childitem -name

Description
-----------
This command retrieves only the names of items in the current directory.





See Also

Concepts

FileSystem プロバイダー

Other Resources

Clear-Content
Get-Content
Get-ChildItem
Get-Content
Get-Item
Remove-Item
Set-Content
Test-Path