Created
April 3, 2020 09:55
-
-
Save KaustubhPatange/239ad929bf2abcc5e2496380cfb6d241 to your computer and use it in GitHub Desktop.
An utility to clean temp files in project.
This file contains 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
# Created by Kaustubh Patange | |
# Date Modified: 3rd April 2020 | |
# | |
# @Platform: Windows (only) - A Powershell script | |
# | |
# @Summary: We often get into some space issues during coding, especially when you are | |
# doing Android development (native) in Android Studio which exceptionally | |
# creates larger gradle downloads and stuff. This is applicable also for | |
# flutter, Xamarin or even a standard .Net project, etc. | |
# | |
# For eg: A standard 200KB github cloned Android project goes up to 60+MB | |
# after buld. Sometimes you don't need such project. Sure you can delete | |
# those files manually but deleting those in many such projects is a | |
# tiresome process. | |
# | |
# In such case this script will help you to automatically delete this. | |
# | |
# @Usage: 1. Copy this whole text to file name anything.ps1 | |
# 2. Run this script once so that it creates some default profiles. | |
# Remember to read console output. | |
# 3. Now open a powershell window and type | |
# anything.ps1 -path path-to-folder | |
# | |
# Once you run this it will recursively search for the folders trailing with those | |
# prefixes present in clean-includes.txt file (same folder) and will remove them. | |
# | |
# "Alternatively" copy this .ps1 file to any folder where you want to run this script. | |
# Now right click > Run with powershell and it will do it's job. | |
# | |
# @Licensed: Under MIT https://opensource.org/licenses/MIT | |
# | |
# | |
param([String]$path = (Get-Location).Path) | |
$filePath = "clean-includes.txt" | |
$defaultProfiles = @" | |
\build | |
\.gradle | |
\.circleci | |
\.idea | |
\Debug | |
\Release | |
"@ | |
if (-Not (Test-Path $filePath)) { | |
Write-Output "Piping profile file => $filePath" | |
New-Item $filePath -type file | Out-Null | |
Write-Output "Appending default profiles" | |
Add-Content -Path $filePath -Value $defaultProfiles | |
Write-Output "`n`[*] Add your profiles to $filePath, this file contains all the prefixes which will delete the trailing folders.`n`Once done, run the script again!`n` " | |
Read-Host -Prompt "Press Enter to continue" | |
return | |
} | |
$profiles = Get-Content -Path $filePath | |
Write-Output "Removing from $path..." | |
$folders = Get-ChildItem -Path path -Recurse -Directory | |
foreach ($folder in $folders) { | |
$folderPath = ([System.IO.DirectoryInfo]$folder).FullName | |
foreach ($profile in $profiles) { | |
if (($folderPath).contains($profile) -and (Test-Path $folderPath)) { | |
Remove-Item "$folderPath" -Recurse | |
} | |
} | |
} | |
Write-Output "Done!" | |
Read-Host -Prompt "Press Enter to continue" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alternatively, you can save this
clean-proj.ps1
file inC:\Windows
directory and use it globally through powershell.