How to insert a new line at the beginning of a big TXT file?

M

Morris

I searched through the group but couldn't anything helpful..
I've got this 56k lines, 8 megabytes txt file and I need to insert one
line at the very beginning. I'm thinking of two possibilities:

1) To open the file for append, then somehow move onto the beginning of
it, instert new line, close

2) create a new file, insert new line, then somehow append the new file
with the content of the big file.


Which method is at all possible in VBA? If both - which would be
faster?

Cheers,
morris
 
S

Stefan Hoffmann

hi Morris,
1) To open the file for append, then somehow move onto the beginning of
it, instert new line, close
Won't work.
2) create a new file, insert new line, then somehow append the new file
with the content of the big file.
Create your file with your new line. Store it as a template. Copy
template+data into new file using

Shell "COPY TEMPLATE+DATA NEWFILE".

or with ShellExecute from

http://www.mvps.org/access/api/api0018.htm


mfG
--> stefan <--
 
M

Morris

Create your file with your new line. Store it as a template. Copy
template+data into new file using

Shell "COPY TEMPLATE+DATA NEWFILE".

I'm afraid I don't really know what you mean....
 
S

Stefan Hoffmann

hi Morris,
I'm afraid I don't really know what you mean....
Create a text file containing your empyt line. Name it TEMPLATE.TXT.
Now you can enter

COPY TEMPLATE.TXT+OLDFILENAME.EXT NEWFILENAME.EXT

on the command-line, which will give you your desired result.

The command-line part can be called from code with the Shell or
ShellExecute method.

mfG
--> stefan <--
 
M

Morris

Create a text file containing your empyt line. Name it TEMPLATE.TXT.
Now you can enter

COPY TEMPLATE.TXT+OLDFILENAME.EXT NEWFILENAME.EXT

on the command-line, which will give you your desired result.

The command-line part can be called from code with the Shell or
ShellExecute method.

Allright, using command-line/dos 'copy' syntax!



Thanks a lot!! :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top