Created
October 10, 2021 03:47
-
-
Save QZLin/0d91005d0163cca130d694932ab1b33e to your computer and use it in GitHub Desktop.
clean all files accord to file type list in dir and subdir
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
# example: c/c++ build clean | |
$clean_types = 'o', 'obj', 'res', 'gch', 'pch', 'exe', 'out' | |
Write-Output "Clean $clean_types" | |
# Remove `–Recurse` if subdir not need clean | |
Get-ChildItem –Recurse | ForEach-Object { | |
$file = $_ | |
try { | |
foreach ($type in $clean_types) { | |
### !!!Warning!!! Check match parttern carefully, removed file will not be recover simply | |
if ($file -match "\.$type`$") { | |
Remove-Item $file -ErrorAction Stop | |
} | |
} | |
} | |
catch { | |
Write-Output "RM File Error :$file $_" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment