Skip to content

Instantly share code, notes, and snippets.

@QZLin
Created October 10, 2021 03:47
Show Gist options
  • Save QZLin/0d91005d0163cca130d694932ab1b33e to your computer and use it in GitHub Desktop.
Save QZLin/0d91005d0163cca130d694932ab1b33e to your computer and use it in GitHub Desktop.
clean all files accord to file type list in dir and subdir
# 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