Skip to content

Instantly share code, notes, and snippets.

@amay077
Created January 29, 2018 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amay077/d97cb33cd10a958619d1b45809a876fd to your computer and use it in GitHub Desktop.
Save amay077/d97cb33cd10a958619d1b45809a876fd to your computer and use it in GitHub Desktop.
Script for delete bin/ and obj/ directory in child directories.
$dirs = Get-ChildItem -Recurse * | ? { $_.PSIsContainer} | % { $_.FullName} | grep -e bin$ -e obj$
foreach ($dir in $dirs) {
# echo $dir
rm -rf $dir
}
@stknohg
Copy link

stknohg commented Jan 30, 2018

より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