Jump to content

APPEND DATA TO AN EXISTING FILE


Recommended Posts

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
Link to comment
Share on other sites

  • Moderators

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?

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.

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


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

Link to comment
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


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

Link to comment
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

Edited by kjactive
Link to comment
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.

Link to comment
Share on other sites

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