Jump to content

Changing File


Guest urifoox
 Share

Recommended Posts

Guest urifoox

Hi All,

New to AutoIt, quick question. I have a file with 5 lines, I want to read the file, and modify the fifth line? In Perl I would just pipe the file to an array, make a $counter, up the $counter until 5, then just append to the line.

I'm assuming the process is similar in AutoIt, can anyone give me the code and walk me through it?

Thanks.

Link to comment
Share on other sites

Guest urifoox

Try the helpfile. FileOpen comes to mind.

<{POST_SNAPBACK}>

Nevermind...I got it.

;** Variables

$count = 1

Dim $aArray[6]

;** Create Array

$file = FileOpen("c:\abc", 0)

While $count <= 5

$chars = FileReadLine($file)

If @error = -1 Then ExitLoop

$aArray[$count] = $chars

$count = $count + 1

Wend

fileclose("c:\abc")

;** Rewrite File

$count2 = 1

$file = FileOpen("c:\abc", 2)

while $count2 < $count

if $count2 = 5 then

FileWriteline($file, $aArray[$count2] & " New Text")

else

FileWriteline($file, $aArray[$count2])

endif

$count2 = $count2 + 1

Wend

fileclose("c:\abc")

Might not be the prettiest, but it works.

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...