Skip to content

Instantly share code, notes, and snippets.

@gpoole
Created July 6, 2020 00:55
Show Gist options
  • Save gpoole/4c60b683617141c8742b13f6d7c341fa to your computer and use it in GitHub Desktop.
Save gpoole/4c60b683617141c8742b13f6d7c341fa to your computer and use it in GitHub Desktop.
Delete image files that don't have any name references in source files
function FindAny() {
param($name)
$found = Get-ChildItem . -Recurse -Include *.js, *.css, *.html, *.xml |
? { $_.FullName -notmatch "node_modules" -and $_.FullName -notmatch "bower_components" } |
Select-String $name
return ($found | Measure-Object -Line).Lines -gt 0;
}
Get-ChildItem "web\images" | ? { -Not (FindAny $_.Name) } | rm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment