Created
July 25, 2025 20:36
-
-
Save TimothyK/0b9d5d96b4a17e9422b0b7d34eb12633 to your computer and use it in GitHub Desktop.
PowerShell script to remove bin and obj folders resursively
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
| ############## | |
| # Parameters | |
| ############## | |
| param ( | |
| [Parameter(Mandatory = $true)] | |
| [string] $folderPath | |
| ) | |
| # Functions | |
| function Remove-BinAndObjFolders { | |
| param ( | |
| [string]$path | |
| ) | |
| # Check if the path exists | |
| if (Test-Path $path) { | |
| # Get all subdirectories in the current directory | |
| $subDirectories = Get-ChildItem -Path $path -Directory | |
| # Loop through each subdirectory | |
| foreach ($directory in $subDirectories) { | |
| # Check if the directory name is "bin" or "obj" | |
| if ($directory.Name -eq "bin" -or $directory.Name -eq "obj") { | |
| # Delete the directory | |
| Remove-Item -Path $directory.FullName -Recurse -Force | |
| Write-Host "Deleted $($directory.FullName)" | |
| } | |
| else { | |
| # If it's not "bin" or "obj", recursively call the function | |
| Remove-BinAndObjFolders -path $directory.FullName | |
| } | |
| } | |
| } | |
| else { | |
| Write-Host "Path $path does not exist." | |
| } | |
| } | |
| # Main | |
| Remove-BinAndObjFolders -path $folderPath |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment