Monday 24 February 2020

Images used in web project

I am doing little clean-up in the project. Need to identify what images are still used and the rest I would like to remove. This PowerShell script helps to identify images which are used in any page, user control or c# code.

For each in the application is executed command which tries to find its name in all files matching given pattern.


@(Get-ChildItem 'D:\WebApp\images') | 
    ForEach-Object { 
        $_.name | Write-Host -NoNewline
        Write-Host ' ' -NoNewline
        
        dir 'D:\WebApp' -I *.aspx,*.ascx,*.cs,*.master -R | 
            Select-String $_.name -Quiet | where  {$_ -eq $true} | Write-Host -NoNewline
        
        Write-Host #writes a new line
    }