Sign in to follow this  
Followers 0
AllSystemGo

_FileWriteFromArray explanation

5 posts in this topic

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Thank you for your help Weaponx.

You were right in the version 3.12.0 it got fixed and it's out already!!

Cheers

Share this post


Link to post
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
Sign in to follow this  
Followers 0