PowerShell Regex to Replace alt With Image Filename -
so have code far:
that regex finds images not have alt tags in them.
i want take 1 step further adding in alt attribute content inside of it, being name of image src attribute.
as always, advice or appreciated.
if know automate function does, here go:
function automate($school, $query, $replace) { $processfiles = get-childitem -exclude *.bak -include "*.html", "*.html", "*.htm", "*.htm" -recurse -path $school foreach ($file in $processfiles) { #$text = get-content $file $text = get-content $file | out-string $text = $text -replace $query, $replace $text | out-file $file -force -encoding utf8 } }
try this:
get-childitem -exclude *.bak -include *.html, *.htm -recurse -path $school | % { $html = new-object -com htmlfile $html.write([io.file]::readalltext($_.fullname)) $html.getelementsbytagname('img') | % { $_.alt = split-path -leaf $_.src } [io.file]::writealltext($html.documentelement.outerhtml) }
Comments
Post a Comment