亀の甲羅2

今日もまた朝とく起きて励まなん窓に明るきありあけの月

powershell 特定のファイル名のみ削除

これも定型パターンでしょう。
今回は拡張子でパターンを指定してみた。(-Filterはワイルドカード指定っぽい)

$directory = "C:\hogehoge"
Get-ChildItem -Path $directory -Filter *.jpg2 -Recurse | ForEach-Object { Remove-Item -LiteralPath $_.FullName }

別解としては、こんな感じかな。

$path = "C:\hogehoge"
$pattern = ".*.jpg2"
Get-ChildItem -Path $path -Recurse | Where-Object { $_.Name -match $pattern } | Where-Object { !$_.PSIsContainer } | %{Remove-Item -LiteralPath $_.FullName }