Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing to top of a file

Status
Not open for further replies.

ihaveaproblem

Programmer
Jul 4, 2003
14
0
0
GB
I have generated an app which does some overnight processing. As part of this I am writing some specific results and any errors to a couple of log files. Trouble is these are writing to the bottom of the file as default.

Does anybody know how I would write these simple messages to the top of the file?

I am using

Open LogFile1 For Append As #1
Print #1, "The data I need to see in the Log"

Cheers
 
as an easy way, are you considered writing TMP file then addind to it
( smth like
copy tmp+LogFile1 LogFile1
)?
Ok, in that exaxt form it didn't go.
And in this did:
copy tmp+LogFile1 tmp2
del LogFile1
ren tmp2 LogFile1

What I have here are DOS commands (to be executed via shell). Probably this could be done via FSO as well.
 
Hi,

Use
Code:
Print #1, "The data I need to see in the Log"; Tab(1)

Jordi Reineman
 
Open a temporary file in Output mode and write your new data to it.
Open your LogFile in Input mode.
Read all the contents of your LogFile and write them to the temporary file.
Close both files.
Delete the LogFile.
Rename the temporary file as LogFile.

Open "Temp.txt" for Output as #1
Print #1, (New Data)
Open "LogFile1" for input as #2
Do while not EOF(2)
Line Input #2, (Existing Data)
Print #1, (Existing Data)
Loop
Close #1
Close #2

Kill "LogFile1"
Name "Temp.txt" as "LogFile1"

You will need to include the paths with the file names.

Good luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top