AlanTsai
2/12/2018 - 7:42 AM

[Remove packages, bin and obj folder 刪除 packages,bin和obj資料夾] 用來快速清理solution裡面非必要檔案減少空間 #powershell

[Remove packages, bin and obj folder 刪除 packages,bin和obj資料夾] 用來快速清理solution裡面非必要檔案減少空間 #powershell

# 看看那些會刪掉

dir -Directory -Recurse -Include bin,obj  | %{$_.FullName}

# 實際刪掉
dir -Directory -Recurse -Include bin,obj  | Remove-Item -Force -Recurse
# 看看那些會刪掉

dir -Directory -Recurse -Include packages | %{$_.FullName}

# 實際刪掉

dir -Directory -Recurse -Include packages | Remove-Item -Force -Recurse

# 如果有些檔案的資料夾名稱也會包含packages,但是不應該刪掉
# 例如要保留資料夾名稱有 \Developer\Packages和 App_Data\Packages
# 那麼做法如下
# 使用where不是exclude是因為exclude只包含檔名,不包含路徑

dir -Directory -Recurse -Include packages | Where {$_.FullName -notlike "**\Developer\Packages" -and $_.FullName -notlike "*\App_Data\packages"}  | %{$_.FullName}

# 實際刪掉

dir -Directory -Recurse -Include packages | Where {$_.FullName -notlike "**\Developer\Packages" -and $_.FullName -notlike "*\App_Data\packages"}  | Remove-Item -Force -Recurse