Recently I needed to do a bit of cleanup as in one project after many UI changes, where we moved or changed structure of pages, were left resource files which no longer had corresponding page or user control.
Nobody likes doing such cleanup manually so I come up with short powershell script which went though individual resource files and try to identify if it is still needed or not.
Explanation:
- Find all files in folder with local resources (e.g. workflow.aspx.en-US.resx)
- For each file remove the suffix e.g. en-US.resx
- Remove the subdirectory from name in order to get name of the page worflow.aspx
- Get each file just once (there can be multiple language mutations)
- Check if the file exists
- Write out only those where the file was not found
$res_location = "./App_LocalResources/" Get-ChildItem -Path $res_location -Name | ForEach-Object -Process {"$res_location$_" -ireplace "(.[a-z]{2}-[a-z]{2})?.resx",""} | ForEach-Object -Process {$_.Replace($res_location, "")} | Get-Unique | ForEach-Object -Process {Write-Output "$_ $(Test-Path $_ -PathType Leaf)"} | where { $_ -match "False" }