Change the Title EnMasse of HTML Pages
Keywords: change title html
Question:
I am trying to change the title tag of HTML document. I want to create a macro or script that can automaticaly change the TITLE tag of all the HTML files in the folder to the file name. Help!!!Answer:
This example uses the Binary Tag operations as suggested:
- Understand how the BinaryTag functions works.
For a good tutorial on the BinaryTag functions download the HTML DIALOG extender and read the tutorial. Don't actually use that extender, but just understand what the BinaryTag functions are doing in the tutorial.
- Write a script that can modify ONE file the way oyu want.
- Then it will be easy to modify the script to process all the files you want. Either a directory or even an entire directory tree.
UseHtmlFile="C:\TEMP\filedata.html" Tempfile="C:\TEMP\filerslt.html" newtitle = "Hello World" bb=BinaryAlloc(100000) BinaryRead(bb,UseHtmlFile) Structure=BinaryTagInit(bb,"") ;BinaryTagInit returns a special value ;that we call a structure. WIL uses the ;structure to keep track of what is ;going on. While 1 ;means loop forever – at least until ;a break statement elsewhere causes the ;exit to the loop structure=BinaryTagFind(structure) ;The BinaryTagFind function instructs WIL ;to locate the next tagged keyword. It ;knows where to start from the information ;passed to it in the structure variable, ;and it saves updated information also in ;the structure variable. if structure=="" then break ;If the structure variable comes back ;from the BinaryTagFind as a null string, ;then no more tagged keywords were found ;and it is time to break out of the ;loop wbdata=BinaryTagExtr(structure,1) ;The BinaryTagExtr function extracts the ;text in between the tags. Leading and ;trailing whitespace is deleted. ;In addition, the 1 option indicates that ;tabs and line terminators should be ;removed and spaces inserted if required. structure=BinaryTagRepl(structure,strCat("")) ;The BinaryTagRepl takes the string and the ;structure variable is updated with new information. Endwhile BinaryWrite(bb,tempfile) ;The BinaryWrite writes out the modified ;HTML file to a tempfile. BinaryFree(bb) ;The memory used by the BinaryBuffer is now returned to the system. exit
Article ID: W15341