Sign in to follow this  
Followers 0
MaCgyver

APPEND DATA TO AN EXISTING FILE

11 posts in this topic

#1 ·  Posted (edited)

I am looking on the help file, but can't seem to find where I can append data to a file. What am I overlooking? :o

I basically want to send the data from one file(file x) to another file (file y). File X gets overwritten throughtout the day with new data. Before the data in file X is overwritten I want to send that data to file Y. File Y will be used at the end of the day to create a report.

Edited by MaCgyver

Share this post


Link to post
Share on other sites



I am looking on the help file, but can't seem to find where I can append data to a file. What am I overlooking? :o

Care to try to be a tad bit more specific?

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

I am looking on the help file, but can't seem to find where I can append data to a file. What am I overlooking? :o

FileWriteLine appends to a file.


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

SmoKe N

Looking to read from one file and append the data in the file to another file throught the day.

BidDog you answered my question. Thanks

Share this post


Link to post
Share on other sites

SmoKe N

Looking to read from one file and append the data in the file to another file throught the day.

BidDog you answered my question. Thanks

You are welcome and the name is BigDod.

Why is everyone calling me BigDog now, perhaps I should change it



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

You have to provide an argument to FileOpen(FileName and Path, mode argument)

$ID = FileOpen(File, mode) // open file for writing

IF @error Then Return 1 // check for errors

FileWriteLine($ID, text) // write text related to the mode tag in fileopen

FileClose($ID) // close the file again

Modes:

0 = Read mode

1 = Write mode (append to end of file)

2 = Write mode (erase previous contents)

4 = Read raw mode

8 = Create directory structure if it doesn't exist (See Remarks).

One can seek into specified locations in the text and insert from this point too and offcourse if one sets the read mode one has to use FileReadLine($ID) and not FileWriteLine( but still remember to close the text at the end. It's posible to use FileWriteLine(/ FileReadLine( without the open/close functions but this is just very slow especially with large texts..

kjactive :o

Edited by kjactive

Share this post


Link to post
Share on other sites

You have to provide an argument to FileOpen(FileName and Path, mode argument)

$ID = FileOpen(File, mode) // open file for writing

IF @error Then Return 1 // check for errors

FileWriteLine($ID, text) // write text related to the mode tag in fileopen

FileClose($ID) // close the file again

Modes:

0 = Read mode

1 = Write mode (append to end of file)

2 = Write mode (erase previous contents)

4 = Read raw mode

8 = Create directory structure if it doesn't exist (See Remarks).

One can seek into specified locations in the text and insert from this point too and offcourse if one sets the read mode one has to use FileReadLine($ID) and not FileWriteLine( but still remember to close the text at the end. It's posible to use FileWriteLine(/ FileReadLine( without the open/close functions but this is just very slow especially with large texts..

kjactive :o

I basically want to send the data from one file(file x) to another file (file y). File X gets overwritten throughtout the day with new data. Before the data in file X is overwritten I want to send that data to file Y. File Y will be used at the end of the day to create a report.

Share this post


Link to post
Share on other sites

maybe

$data = FileRead($file_x, FileGetSize($file_x))

FileWrite($file_y, $data)

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

maybe

$data = FileRead($file_x, FileGetSize($file_x))

FileWrite($file_y, $data)

8)

Before I read what you wrote I tried this, but it pauses for some reason. I'm thinking what you wrote is sort of what I put together, but I will try to make it simpler.

$file = FileOpen('c:\scripts\testing2.csv', 0)

$file2 = FileOpen('c:\scripts\testing.csv', 1)

; Check if file opened for reading OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

; Read in lines of text until the EOF is reached

While 1

$line = FileReadLine($file)

FileWriteLine($file2, $line)

If @error = -1 Then ExitLoop

Wend

FileClose($file)

FileClose($file2)

Edited by MaCgyver

Share this post


Link to post
Share on other sites

you error checking needs to be right after the READ

$line = FileReadLine($file)

If @error = -1 Then ExitLoop

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

you error checking needs to be right after the READ

$line = FileReadLine($file)

If @error = -1 Then ExitLoop

8)

That was it!! Thanks :o

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