Jump to content

Recommended Posts

Posted

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

 

Posted

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

Posted (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 by 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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