bensp381 Posted April 7, 2012 Share Posted April 7, 2012 ;initial data.txt example below ;data in the source file will be in formats like below, where commas ;present it will already have apostrophes so it will not affect the output csv file. ;Line1 ;"Line, 2" ;"I am line, 3" ;4 ;Line 5 #include <array.au3> #include <file.au3> Local $sOutput = "New Line" & "," Local $hFile = "initialdata.txt" ; Path to file $hFile = FileOpen($hFile, 0) If $hFile = -1 Then _ErrorMsg("Unable to open text file.") Local $sData = FileRead($hFile) If @error Then _ErrorMsg("Unable to read text file.") $sOutput &= $sData ; Concatenate ConsoleWrite($sOutput) Func _ErrorMsg($sMessage) MsgBox(0, "Error", $sMessage) Exit Local $file = FileOpen("test.txt", 1) ; Check if file opened for writing OK If $file = -1 Then MsgBox(0, "Error", "Unable to output file test.txt") Exit EndIf FileWriteLine($file, $sData) FileClose($file, $hFile) EndFuncHi guys, This is my first post on this forum, I usually manage to work out whatever scripts I need from your helpful advice, however on this occasion I am a bit stuck, I have tried to write a script which will read a simple txt file, group each line together onto a single line with a comma to separate them and output the result to a csv file onto a new line ( output file will already exist ) I will try to attach what I have already below. Any help would be great thank you. readwrite.au3readwrite.au3 Link to comment Share on other sites More sharing options...
AutoBert Posted April 8, 2012 Share Posted April 8, 2012 (edited) to solve your problem ou can use _ReplaceStringInFile . This func works only whith txt-files. Just look into the helpfile for the syntax greetings from germany autoBert Edited April 8, 2012 by AutoBert Link to comment Share on other sites More sharing options...
bensp381 Posted April 9, 2012 Author Share Posted April 9, 2012 Hi autoBert, Thank you for your advice, I have been looking into using _ReplaceStringInFile however it seems to me that I could only replace things already in the file, I seem to be having more trouble with the new variables getting written into a new file, Im sure I have done correctly, or almost correctly but I cant seem to figure out where I have gone wrong. Thank you for your help Kindest Regards Ben 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