DeeCee Posted February 15, 2006 Share Posted February 15, 2006 Hey folks, I'm trying to build a hyper-linked (HTML) TOC for several hundred small text files that we have stored on our company server and can't seem to get my noggin wrapped around a solution. Using OpenOffice Calc, I've built a pipe delimited file like so: pagenumber|topic-blah-blah|11/01/05| pagenumber|topic-blah-blah|11/02/05| pagenumber|topic-blah-blah|11/03/05| pagenumber|topic-blah-blah|11/04/05| What I'm trying to do is create a link based on the first column with the other two fields just plain text. I can parse the individual fields into an array without any problems, but... ...using StringReplace replaces *all* of the pagenumber fields with the exact same html string that I've assembled. I've tried this at least a dozen different ways without any luck, so in simple terms, how do I use FileReadLine and FileWriteLine to do each line separately? I'm fairly new to using AutoIt and would appreciate any general suggestions on how to set up the structure of the code... -DeeCee- Link to comment Share on other sites More sharing options...
CyberSlug Posted February 15, 2006 Share Posted February 15, 2006 Hope this helps Dim $input_file_name = ".\input.txt" Dim $output_file_name = ".\output.html" $file = FileOpen($input_file_name, 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $info = StringSplit($line, "|") ; Thus $info[1] is pageNumber, $info[2] is topic, $info[3] is date FileWriteLine($output_file_name, '<a href="' & $info[1] & '">' & "link text goes here" & '</a>' & ' ' & $info[2] & ' ' & $info[3] & " <br/>") Wend FileClose($file) Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
Stumpii Posted February 15, 2006 Share Posted February 15, 2006 This should get you started (copied from the trusty help file). $Readfile = FileOpen("Read.txt", 0) $Writefile = FileOpen("Write.txt", 1) ; Check if file opened for reading OK If $Readfile = -1 Then MsgBox(0, "Error", "Unable to open Readfile file.") Exit EndIf ; Check if file opened for writing OK If $Writefile = -1 Then MsgBox(0, "Error", "Unable to open Writefile file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($Readfile ) If @error = -1 Then ExitLoop FileWriteLine($Writefile , $line) Wend FileClose($Writefile ) FileClose($Readfile ) Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity. Link to comment Share on other sites More sharing options...
billmez Posted February 15, 2006 Share Posted February 15, 2006 (edited) Hey folks, I'm trying to build a hyper-linked (HTML) TOC for several hundred small text files that we have stored on our company server and can't seem to get my noggin wrapped around a solution. Using OpenOffice Calc, I've built a pipe delimited file like so: pagenumber|topic-blah-blah|11/01/05| pagenumber|topic-blah-blah|11/02/05| pagenumber|topic-blah-blah|11/03/05| pagenumber|topic-blah-blah|11/04/05| What I'm trying to do is create a link based on the first column with the other two fields just plain text. I can parse the individual fields into an array without any problems, but... ...using StringReplace replaces *all* of the pagenumber fields with the exact same html string that I've assembled. I've tried this at least a dozen different ways without any luck, so in simple terms, how do I use FileReadLine and FileWriteLine to do each line separately? I'm fairly new to using AutoIt and would appreciate any general suggestions on how to set up the structure of the code... -DeeCee- Try this: [edit] Other examples were posted while I was putting this together for you. I think the direction is the same in all examples [/edit] pagenumber|topic-blah-blah|11/01/05| pagenumber|topic-blah-blah|11/02/05| pagenumber|topic-blah-blah|11/03/05| pagenumber|topic-blah-blah|11/04/05| ; Loop the file using FileReadLine ; $FileLine is each line as read ; since the line ends in a pipe, $Fields[4] will be empty $Fields = StringSplit ($FileLine, "|") $link = $Fields[1] $TopicBlah = $Fields[2] $Date = $Fields[3] $FullLink = '<a href="http://' & $link & '">' & $TopicBlah & '</a>' HTH, billmez Edited February 15, 2006 by billmez Link to comment Share on other sites More sharing options...
DeeCee Posted February 15, 2006 Author Share Posted February 15, 2006 Thank you all very much!This should get you started (copied from the trusty help file).I've been all over the help file for several days now... I must really be losing it. (either tht or I just couldn't see the forest for all the trees.) -DeeCee- Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now