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!

IMPORTANT!! File Manipulation

Status
Not open for further replies.

Goha

IS-IT--Management
May 9, 2002
91
0
0
US
How do I add a record (constant header) to the begginning of a file?


 
To the beginning of a text file?

Open the text file, read the existing data into you variable or array. Here is a starting point...


dim ff as integer
dim inputdata as string
dim outputdata as string

ff=freefile

Open "textfile.txt" for INPUT as #ff
input #ff, inputdata
close #ff

' if you are 100% sure you read all the data safely
' you can kill the textfile.txt
' but I wouldn't do it just yet

outputdata = "your header info goes here" & vbcrlf
outputdata = outputdata & inputdata

Open "newtextfile.txt" for OUTPUT as #ff
Print #ff, outputdata
Close #ff

' keep in mind that the input will only read up to the end of the first line, so you may have to loop through this until eof(ff) = true or do while eof(ff) = false

' build an array of inputdata

gotta go for now, hope this helps get you started.
Tuna - It's fat free until you add the Mayo!
 
Or...

Open the source file as read-only and create a second file in write mode. Add the data you want to the start of the second file, then append the contents of the first file to the second file. Delete the first file afterwards, or rename it as a backup file.

TheTuna's method is hard on memory, mine is hard on disk space. Pick the one that works for your application.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top