Created
January 29, 2018 08:59
-
-
Save amay077/d97cb33cd10a958619d1b45809a876fd to your computer and use it in GitHub Desktop.
Script for delete bin/ and obj/ directory in child directories.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$dirs = Get-ChildItem -Recurse * | ? { $_.PSIsContainer} | % { $_.FullName} | grep -e bin$ -e obj$ | |
foreach ($dir in $dirs) { | |
# echo $dir | |
rm -rf $dir | |
} |
よりPowerShellらしく(外部コマンドを使わない)ということであればこういうのはいかがでしょうか。
# PowerShell Core 6.0 Win/Linuxで動作確認
# エイリアスを使わない場合
$dirs = Get-ChildItem -Recurse -Directory | Where-Object { $_.Name -in ('bin', 'obj') }
foreach ($dir in $dirs) {
#$dir.Fullname
Remove-Item $dir.Fullname -Recurse -Force -Verbose #-WhatIf
}
# エイリアスを使う、パラメーター名を可能な限り短くした場合
$dirs = dir -R -Di | ? { $_.Name -in ('bin', 'obj') }
foreach ($dir in $dirs) {
#$dir.Fullname
ri $dir.Fullname -R -Fo -V #-WhatIf
}
# パイプラインで一本化した場合
dir -R -Di | ? { $_.Name -in ('bin', 'obj') } | % { ri $_.Fullname -R -Fo }
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks: