openaccount1
asked on
Tranform Special characters to entity Name recursively
Hi,
On one question posted here in EE I asked someone how to change texts to their entity names and jostrander provided the answer. But what we want next is
(1) Make the pages retain their names because currently the page is being renamed to new.html
(2) make the code search and transform for pages recursively or on multiple subfolders and subfolder of subfolders.
Here is the question posted as a reference on how the code works.
https://www.experts-exchange.com/questions/25224676/Convert-Text-to-UTF-8-Format-or-Source-code-format.html
Below is the vb script code and a sample html page.
On one question posted here in EE I asked someone how to change texts to their entity names and jostrander provided the answer. But what we want next is
(1) Make the pages retain their names because currently the page is being renamed to new.html
(2) make the code search and transform for pages recursively or on multiple subfolders and subfolder of subfolders.
Here is the question posted as a reference on how the code works.
https://www.experts-exchange.com/questions/25224676/Convert-Text-to-UTF-8-Format-or-Source-code-format.html
Below is the vb script code and a sample html page.
SourceDir=replace(wscript.scriptfullname,wscript.scriptname,"")
Set oDict=CreateObject("Scripting.Dictionary")
MakeDictionary
Set fso=CreateObject("Scripting.FileSystemObject")
set oFile=fso.OpenTextFile(SourceDir & "original.html",1)
OriginalText=oFile.ReadAll
oFile.close
arrText=split(OriginalText,vbCrLf)
for each line in arrText
for i = 1 to len(line)
myChar=mid(line,i,1)
If asc(myChar)>=160 and asc(myChar)<=255 then
newText=newText & oDict.Item(myChar)
Else
newText = newText & myChar
End If
myChar=""
next
newText=newText & vbCrLf
next
set newFile=fso.OpenTextFile(SourceDir & "new.html",2,true)
newFile.writeline newText
newFile.close
msgbox "All done!",vbInformation,"Test replace 2"
Sub MakeDictionary
oDict.Add "¡","¡"
oDict.Add "¢","¢"
oDict.Add "£","£"
oDict.Add "¤","¤"
oDict.Add "¥","¥"
oDict.Add "¦","¦"
oDict.Add "§","§"
oDict.Add "¨","¨"
oDict.Add "©","©"
oDict.Add "ª","ª"
oDict.Add "«","«"
oDict.Add "¬","¬"
oDict.Add "","­"
oDict.Add "®","®"
oDict.Add "¯","¯"
oDict.Add "°","°"
oDict.Add "±","±"
oDict.Add "²","²"
oDict.Add "³","³"
oDict.Add "´","´"
oDict.Add "µ","µ"
oDict.Add "¶","¶"
oDict.Add "·","·"
oDict.Add "¸","¸"
oDict.Add "¹","¹"
oDict.Add "º","º"
oDict.Add "»","»"
oDict.Add "¼","¼"
oDict.Add "½","½"
oDict.Add "¾","¾"
oDict.Add "¿","¿"
oDict.Add "×","×"
oDict.Add "÷","÷"
oDict.Add "À","À"
oDict.Add "Á","Á"
oDict.Add "Â","Â"
oDict.Add "Ã","Ã"
oDict.Add "Ä","Ä"
oDict.Add "Å","Å"
oDict.Add "Æ","Æ"
oDict.Add "Ç","Ç"
oDict.Add "È","È"
oDict.Add "É","É"
oDict.Add "Ê","Ê"
oDict.Add "Ë","Ë"
oDict.Add "Ì","Ì"
oDict.Add "Í","Í"
oDict.Add "Î","Î"
oDict.Add "Ï","Ï"
oDict.Add "Ð","Ð"
oDict.Add "Ñ","Ñ"
oDict.Add "Ò","Ò"
oDict.Add "Ó","Ó"
oDict.Add "Ô","Ô"
oDict.Add "Õ","Õ"
oDict.Add "Ö","Ö"
oDict.Add "Ø","Ø"
oDict.Add "Ù","Ù"
oDict.Add "Ú","Ú"
oDict.Add "Û","Û"
oDict.Add "Ü","Ü"
oDict.Add "Ý","Ý"
oDict.Add "Þ","Þ"
oDict.Add "ß","ß"
oDict.Add "à","à"
oDict.Add "á","á"
oDict.Add "â","â"
oDict.Add "ã","ã"
oDict.Add "ä","ä"
oDict.Add "å","å"
oDict.Add "æ","æ"
oDict.Add "ç","ç"
oDict.Add "è","è"
oDict.Add "é","é"
oDict.Add "ê","ê"
oDict.Add "ë","ë"
oDict.Add "ì","ì"
oDict.Add "í","í"
oDict.Add "î","î"
oDict.Add "ï","ï"
oDict.Add "ð","ð"
oDict.Add "ñ","ñ"
oDict.Add "ò","ò"
oDict.Add "ó","ó"
oDict.Add "ô","ô"
oDict.Add "õ","õ"
oDict.Add "ö","ö"
oDict.Add "ø","ø"
oDict.Add "ù","ù"
oDict.Add "ú","ú"
oDict.Add "û","û"
oDict.Add "ü","ü"
oDict.Add "ý","ý"
oDict.Add "þ","þ"
oDict.Add "ÿ","ÿ"
End Sub
original.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great! Solution is working the first time. Very much thanks for the help.
Dim strFileExtension