# チェックを開始するディレクトリを指定します(適宜変更してください)
$StartDir = "C:\Path\To\Your\Directory"
# 再帰的にディレクトリを取得します
Get-ChildItem -Path $StartDir -Recurse -Directory | ForEach-Object {
# 現在のフォルダ
$CurrentDir = $_
# フォルダが空であるかを確認
if ((Get-ChildItem -Path $CurrentDir.FullName -Force) -eq $null) {
# 親フォルダを取得
$ParentDir = $CurrentDir.Parent
# フォルダ名と親フォルダ名が同じかを確認
if ($CurrentDir.Name -eq $ParentDir.Name) {
# 条件に合致するフォルダを表示
Write-Host "条件に合致するフォルダ: $($CurrentDir.FullName)"
}
}
}
# 条件に合致するフォルダを削除する場合(注意)
Remove-Item -Path $CurrentDir.FullName -Recurse -Force
Write-Host "削除しました: $($CurrentDir.FullName)"