Jump to content

Recommended Posts

Posted

The only problem I had was that exclamation marks were absent from the final file due to delayed expansion enabled, and that's why I asked the original question.

And there we are; the question you asked had nothing to do with a file, your posted scripts do not read from nor do they write to a file.

Do not presume to know more than those off whom you require help, not only is it rude and prevents those people from providing you further help in future, it is also wrong, (your knowledge of the subject is unlikely to ever reach the level of some of our Members).

BTW - just in case you are interested, here is a vbscript, place it along side your INDEX.HTML and double click it, the resulting REPLACED.TXT should be what you required.

Const ForReading = 1, ForWriting = 2strScriptFile = Wscript.ScriptFullNameSet objFSO = CreateObject("Scripting.FileSystemObject")Set objFile = objFSO.GetFile(strScriptFile)strFolder = objFSO.GetParentFolderName(objFile)Set objFile = objFSO.OpenTextFile(strFolder & "\INDEX.HTML", ForReading)Do    strLine = strLine & objFile.ReadLine & vbCrLf       Loop While Not objFile.AtEndOfStreamobjFile.ClosestrLine = Left(strLine, Len(strLine) - 2)strLine = replace_char(strLine)If Not (objFSO.FileExists(strFolder & "\REPLACED.TXT")) Then    objFSO.CreateTextFile(strFolder & "\REPLACED.TXT")End IfSet objFile = objFSO.OpenTextFile(strFolder & "\REPLACED.TXT", ForWriting)objFile.Write(strLine)objFile.CloseFunction replace_char(strRemove)    Dim arrWrapper(1)    Dim arrReplace(5)    Dim arrReplaceWith(5)    arrWrapper(0) = arrReplace    arrWrapper(1) = arrReplace       ' Replace    arrWrapper(0)(0) = "&"    arrWrapper(0)(1) = "?"    arrWrapper(0)(2) = "<"    arrWrapper(0)(3) = ">"    arrWrapper(0)(4) = "!"    arrWrapper(0)(5) = "|"        ' With    arrWrapper(1)(0) = "{#}"    arrWrapper(1)(1) = "{##}"    arrWrapper(1)(2) = "{###}"    arrWrapper(1)(3) = "{####}"    arrWrapper(1)(4) = "{#####}"    arrWrapper(1)(5) = "{######}"    For N = 0 To 5        strRemove = Replace(strRemove, arrWrapper(0)(N), arrWrapper(1)(N), 1, -1, 0)    Next    replace_char = strRemoveEnd Function

Posted

Yzöwl excellent script.

Here an modified script that I posted earlier, I made it remove all my VBS comments in my HTA

for the demo.

Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")'-> File To Work WithDim Text :Text = "Demo Count Down.hta"'-> Check To See If File Exists  If Fso.FileExists(Text) Then   ReadListText(Fso.GetFile(Text))  Else     WScript.Echo "Missing : " & Text  End If '-> Function To Process Line By Line Text Files  Function ReadListText(T)   Dim i, j, Ts, V1    Set Ts = Fso.OpenTextFile(T.Path, 1)   i = Ts.ReadAll       For Each j In Split(i,vbCrLf)'-> Skips Comment Line For Output    If Not Left(j,3) = "'->" Then      WScript.Echo j    End If      Next    End Function

Here is the code in HTA to change

<SCRIPT LANGUAGE='VBScript'>'-> Resize And Place In Approx Center Of Screen Dim Wth, Hht :Wth = int(401) :Hht = int(155)  window.ResizeTo Wth, Hht  MoveTo ((Screen.Width / 2) - (Wth / 2)),((Screen.Height / 2) - (Hht / 2))'-> Varibles For Runtime  Dim S1, Tm1'-> Window Onload    Function Window_OnLoad()'-> Set The Timer At 90   S1 = 90   Counter()  End Function '-> Counter For Count Down  Function Counter()    If S1 = 0 Then'-> Code Here For Action When Timer Reaches Zero        window.clearTimeout(Tm1)     Tx1.innerHTML="000"    ' CreateObject("Wscript.Shell").Run("shutdown.exe -s -f -t 00"),0,False     CreateObject("Wscript.Shell").Run("shutdown.exe -r -f -t 01"),0,False     window.close()    End If'-> Add Zero To Count Down    If Len(S1) = 1 Then S1 = "00" & S1    If Len(S1) = 2 Then S1 = "0" & S1   Tx1.style.color="#9A0000" :Tx1.innerHTML=S1   S1 = S1 - 1   Tm1=window.setTimeout("Counter()",1000,"VBScript")  End Function  </SCRIPT>
Script output with comments removed

<SCRIPT LANGUAGE='VBScript'> Dim Wth, Hht :Wth = int(401) :Hht = int(155)  window.ResizeTo Wth, Hht  MoveTo ((Screen.Width / 2) - (Wth / 2)),((Screen.Height / 2) - (Hht / 2))  Dim S1, Tm1  Function Window_OnLoad()   S1 = 90   Counter()  End Function   Function Counter()    If S1 = 0 Then     window.clearTimeout(Tm1)     Tx1.innerHTML="000"    ' CreateObject("Wscript.Shell").Run("shutdown.exe -s -f -t 00"),0,False     CreateObject("Wscript.Shell").Run("shutdown.exe -r -f -t 01"),0,False     window.close()    End If    If Len(S1) = 1 Then S1 = "00" & S1    If Len(S1) = 2 Then S1 = "0" & S1   Tx1.style.color="#9A0000" :Tx1.innerHTML=S1   S1 = S1 - 1   Tm1=window.setTimeout("Counter()",1000,"VBScript")  End Function  </SCRIPT>

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...