aa2zz6 Posted December 13, 2017 Share Posted December 13, 2017 I am trying to combine multiple lines in a text file but I can't seem to get it quite right. I tried using the _FileReadToArray to load in everything from the text document and then I tried using the _FileWriteFromArray to rewrite it as 1 string and replace the original document but it doesn't seem to let me replace the original and when I create a variable to hold the results from the $array it doesn't post anything. Script will do nothing. Text file: Line 1: Loading mapping software from the following directory: Line 2: C:\EIS\EIS\Mapping Workspace - Office Use Line 3: ... Line 4: ... ------------------- Results ------------------------------ Combine both to look like: Loading mapping software from the following directory: C:\EIS\EIS\Mapping Workspace - Office Use #include <file.au3> Global $array If _FileReadToArray(@scriptdir & '\ArcGIS_Desktop.txt', $array) Then For $i = 1 To $array[0] ;MsgBox(0, "ArcGIS Software", $array[$i]) ConsoleWrite($array[$i] & " ") _FileWriteFromArray(@scriptdir & '\ArcGIS_Desktop.txt', $array,1) Next Else MsgBox(0, "Error", "Error from Function") EndIf Exit Link to comment Share on other sites More sharing options...
kylomas Posted December 13, 2017 Share Posted December 13, 2017 aa2zz6, Can you explain this further... Quote but it doesn't seem to let me replace the original kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
kylomas Posted December 13, 2017 Share Posted December 13, 2017 (edited) aa2zz6, This works for me... #include <Array.au3> Local $aFile = StringSplit(FileRead(@ScriptDir & '\aa2zz6 help.txt'), @CRLF, 3) Local $out = '' For $1 = 0 To UBound($aFile) - 1 If $aFile[$1] = '' Then ContinueLoop $out &= $aFile[$1] & ' ' Next ConsoleWrite($out & @CRLF) Local $hfl = FileOpen(@ScriptDir & '\aa2zz6 help (final).txt', 2) FileWrite($hfl, $out) FileClose($hfl) file used for testing...aa2zz6 help.txt kylomas Edited December 13, 2017 by kylomas aa2zz6 1 Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
mikell Posted December 13, 2017 Share Posted December 13, 2017 ? $file = @ScriptDir & '\aa2zz6 help.txt' Local $out = StringRegExpReplace(FileRead($file), '\R\s*', " ") Local $hfl = FileOpen($file, 2) FileWrite($hfl, $out) FileClose($hfl) 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