LoginSignup
0
1

More than 3 years have passed since last update.

コマンドプロンプトとPowerSHellによるファイルとディレクトリの検索

Posted at

※文字列の検索にはWindowsの例によって大文字、小文字の区別は行われません。

コマンドプロンプト

 dir /b /s /A-D ファイル名
 dir /b /s /AD ディレクトリ名

コマンドオプション

 /b:(パスを含む)ファイル名のみを表示する。
 /s:ディレクトリも再帰的に検索する。
 /A-D:ファイルのみを検索する
 /AD:ディレクトリのみを検索する。

ファイル検索

例:index.htmlという名前のファイルを探す

 dir /b /s /A-D index.html
例2:ファイル名の後ろに「.txt」が含まれるファイルを探す
 dir /b /s /A-D *.txt

ディレクトリ検索

例:tmpという名前のディレクトリを探す
dir /b /s /AD tmp

rem 名前の一部に「system」を含むディレクトリを探す(部分一致検索)
dir /b /s /AD *system*

rem 名前の前方に「system」を含むディレクトリを探す(前方一致検索)
dir /b /s /AD system*

rem 名前の後方に「system」を含むディレクトリを探す(後方一致検索)
dir /b /s /AD *system

【PowerShell】

Get-Childitem -Path 検索開始位置 -Include 検索対象の一部 -Recurse -Name
Get-Childitem 検索対象 -Path 検索開始位置 -Recurse -Name [-Directory]

コマンドオプション

 -Path:検索開始位置
 -Include:ファイル名、ディレクトリ名の一部を含むもの
 -Recurse:ディレクトリを再帰的に検索する
 -Name:(パスを含む)ファイル名、ディレクトリ名のみを表示する。
 -Directory:検索対象をディレクトリとする。

ファイル検索

基本形
Get-Childitem 検索ファイル名 -Path c:\ -Recurse -Name
Get-Childitem -include ファイル文字列の一部 -Path c:\ -Recurse -Name
ファイル検索の例
#名前が「windows.txt」のファイルを探す(完全一致)
Get-Childitem windows.txt -path c:\ -Recurse -Name

# 名前の一部に「windows」を含むファイルを探す(部分一致検索)
Get-Childitem -Include *windows* -Path c:\ -Recurse -Name

# 名前の前方に「windows」を含むファイルを探す(前方一致検索)
Get-Childitem -Include windows* -Path c:\ -Recurse -Name 

# 名前の後方に「windows」を含むファイルを探す(後方一致検索)
Get-Childitem -Include *windows -Path c:\ -Recurse -Name

ディレクトリ検索

基本形
Get-Childitem 検索ディレクトリ名 -Path c:\ -Recurse -Name
Get-Childitem -include ディレクトリ文字列の一部 -Path c:\ -Recurse -Name
ディレクトリ検索の例
#名前が「system」のディレクトリを探す(完全一致)
Get-Childitem system -path c:\ -Directory -Recurse -Name

# 名前の一部に「system」を含むディレクトリを探す(部分一致検索)
Get-Childitem -Include system -Path c:\ -Directory -Recurse -Name

# 名前の前方に「system」を含むディレクトリを探す(前方一致検索)
Get-Childitem -Include system* -Path c:\ -Directory -Recurse -Name 

# 名前の後方に「system」を含むディレクトリを探す(後方一致検索)
Get-Childitem -Include *system -Path c:\ -Directory -Recurse -Name
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1