Jump to content

_FileWriteFromArray explanation


Recommended Posts

Ok here is my code, the question is going to follow

#include <File.au3>

Dim $aRecords, $text

$text = FileRead(somefile)

$aRecords = StringSplit($text, @CRLF, 1)

For $x = 1 to $aRecords[0]
    If StringInStr($aRecords[$x], "TB04") Then
        $aRecords[$x] = $aRecords[$x] & " TestJF"
    EndIf
Next

MsgBox(0, "", $aRecords[0])
MsgBox(0, "", $aRecords[1])
MsgBox(0, "", $aRecords[2])

_FileWriteFromArray(somefile,  $aRecords, 1)

So here I read a whole file in memory, then I modify stuff in the array. Until now everything works fine, except when I write to the same file, for some reason it doesn't write from the start of the file it put a blank then start to write. I've check in my array and the blank line isn't in there. What am I doing wrong??

Thank you for your help

Link to comment
Share on other sites

Ok here is my code, the question is going to follow

#include <File.au3>
 
 Dim $aRecords, $text
 
 $text = FileRead(somefile)
 
 $aRecords = StringSplit($text, @CRLF, 1)
 
 For $x = 1 to $aRecords[0]
     If StringInStr($aRecords[$x], "TB04") Then
         $aRecords[$x] = $aRecords[$x] & " TestJF"
     EndIf
 Next
 
 MsgBox(0, "", $aRecords[0])
 MsgBox(0, "", $aRecords[1])
 MsgBox(0, "", $aRecords[2])
 
 _FileWriteFromArray(somefile,  $aRecords, 1)

So here I read a whole file in memory, then I modify stuff in the array. Until now everything works fine, except when I write to the same file, for some reason it doesn't write from the start of the file it put a blank then start to write. I've check in my array and the blank line isn't in there. What am I doing wrong??

Thank you for your help

This is a bug in 3.2.10.0 I think. It should be fixed in 3.2.12.0.
Link to comment
Share on other sites

Wow thxs for the fast reply!! Is there a ETA on when the next update will come out??

BTW: Is there a way to fix that temporarly ??? I mean do I need to parse the whole file and rewrite it??

Edited by AllSystemGo
Link to comment
Share on other sites

Wow thxs for the fast reply!! Is there a ETA on when the next update will come out??

BTW: Is there a way to fix that temporarly ??? I mean do I need to parse the whole file and rewrite it??

You can easily write your own function.

Func _WriteArrayToFile($aArray, $sFilename)
 Local $handle = FileOpen($sFilename,2)
 For $X = 0 to Ubound($aArray)-1
 FileWriteLine($handle,$aArray[$X])
 Next
 FileClose($handle)
 EndFunc
Edited by weaponx
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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