PowerShell Regex to Replace alt With Image Filename -


so have code far:

http://pastebin.com/l4gvlkb1

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

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -