2010-06-09 17:13:59 +0000 2010-06-09 17:13:59 +0000
79
79
Advertisement

Powershell の get-childitem はファイルのみを返すようにする

Advertisement

get-childitemを再帰的に使用したいのですが、ディレクトリではなくファイルのみを返すようにしたいのです。私が持っている最良の解決策は、次のように自然には思えません:

gci . *.* -rec | where { $_.GetType().Name -eq "FileInfo" }
```0x1&
Advertisement
Advertisement

回答 (4)

109
109
109
2013-01-24 21:16:24 +0000

Powershell 3.0では、

gci -Directory #List only directories
gci -File #List only files

これはさらに短く、

gci -ad # alias for -Directory
gci -af # alias for -File
```とシンプルになっています。
78
78
78
2010-06-09 18:06:03 +0000

これを試してみてください。

gci . *.* -rec | where { ! $_.PSIsContainer }
3
Advertisement
3
3
2014-05-19 17:52:55 +0000
Advertisement

PowerShell 3.0 では、新たに追加された -Attributes パラメータ (論理演算子と一緒に)

Get-ChildItem -Recurse -Attributes !Directory+!System

Golfed

dir -r -Attributes !D
``` を使用することもできます。
-5
-5
-5
2015-05-07 11:27:01 +0000

powershell 2.0では、私が考え出した最良かつ最も単純な解決策は、拡張子が

get-childitem -Recurse -include *.*

フォルダには拡張子がないので、それらは除外されます。

Advertisement

関連する質問

2
10
11
14
3
Advertisement
Advertisement