PC Review


Reply
Thread Tools Rate Thread

append to the beginning of a text file

 
 
Eddie Suey
Guest
Posts: n/a
 
      11th Oct 2003
I want to add a new line to the begining of a text file. I dont want to
write over existing data. How do I do this? the file is about 7 mb.


 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      11th Oct 2003
* "Eddie Suey" <(E-Mail Removed)> scripsit:
> I want to add a new line to the begining of a text file. I dont want to
> write over existing data. How do I do this? the file is about 7 mb.


You will have to move the whole contents of the file...

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
 
Reply With Quote
 
I_AM_DON_AND_YOU?
Guest
Posts: n/a
 
      11th Oct 2003
trick:

(1) copy the existing data of notepad file to a textbox1
(2) delete the file.
(3) create the file with same name and copy the new text (which you want to
put in the beginning)
(4) now append the file and copy the contents of textbox1



"Eddie Suey" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> I want to add a new line to the begining of a text file. I dont want to
> write over existing data. How do I do this? the file is about 7 mb.
>
>



 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      11th Oct 2003
Eddie,
As the others have suggested you cannot do this.

Largely because of the size of the file. I would consider writing the new
line to a new file, then using Asynchronous File I/O to append the existing
file on the end of this new file, delete the old file, then rename the new
file to the original name...

Similar to:
http://msdn.microsoft.com/library/de...nousfileio.asp

Hope this helps
Jay

"Eddie Suey" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> I want to add a new line to the begining of a text file. I dont want to
> write over existing data. How do I do this? the file is about 7 mb.
>
>



 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      11th Oct 2003
Hi Eddie,
That is one of first reasons why people started to make databases.
You can now even do more with it,
Maybe a good idea to look if a simple database is not a better approach for
you.
Cor


 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      11th Oct 2003
* "Jay B. Harlow [MVP - Outlook]" <(E-Mail Removed)> scripsit:
> Largely because of the size of the file. I would consider writing the new
> line to a new file, then using Asynchronous File I/O to append the existing
> file on the end of this new file, delete the old file, then rename the new
> file to the original name...


This will change the creation timestamp of the file.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      11th Oct 2003
Herfried,
If the creation timestamp is important, then this would be a downside of the
method.

However! ;-)

I have not played with IO.FileInfo enough, the CreationTime property is read
write, you could 'copy' the attributes from the original file's FileInfo to
the new file's FileInfo and that would update the actual file, thus
preserving the creation timestamp...

Hmm... Touch.NET (simple sample Console Application demonstrating the above)

Public Module MainModule

' args(0) = file to change
' args(1) = properly formatted creation date time

Public Sub Main(ByVal args() As String)
Dim fi As New IO.FileInfo(args(0))
fi.CreationTime = DateTime.Parse(args(1))
End Sub

End Module

Which will set the creation time of the file given to the date given.

Something like:
Touch myfile.txt 10/1/2003

Hope this helps
Jay

"Herfried K. Wagner [MVP]" <hirf-spam-me-(E-Mail Removed)> wrote in message
news:%23PNCj5%(E-Mail Removed)...
> * "Jay B. Harlow [MVP - Outlook]" <(E-Mail Removed)> scripsit:
> > Largely because of the size of the file. I would consider writing the

new
> > line to a new file, then using Asynchronous File I/O to append the

existing
> > file on the end of this new file, delete the old file, then rename the

new
> > file to the original name...

>
> This will change the creation timestamp of the file.
>
> --
> Herfried K. Wagner
> MVP · VB Classic, VB.NET
> <http://www.mvps.org/dotnet>



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      12th Oct 2003
* "Jay B. Harlow [MVP - Outlook]" <(E-Mail Removed)> scripsit:
> If the creation timestamp is important, then this would be a downside of the
> method.
>
> However! ;-)
>
> I have not played with IO.FileInfo enough, the CreationTime property is read
> write, you could 'copy' the attributes from the original file's FileInfo to
> the new file's FileInfo and that would update the actual file, thus


This will work. It was only a little note because most people forget
that the creation date may sometimes be useful...

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      12th Oct 2003
Herfried,
Hey! its an important caveat to note!

Not only that it gave me an opportunity to play with System.IO.FileInfo,
something I have not played with a lot.

Thanks
Jay

"Herfried K. Wagner [MVP]" <hirf-spam-me-(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> * "Jay B. Harlow [MVP - Outlook]" <(E-Mail Removed)> scripsit:
> > If the creation timestamp is important, then this would be a downside of

the
> > method.
> >
> > However! ;-)
> >
> > I have not played with IO.FileInfo enough, the CreationTime property is

read
> > write, you could 'copy' the attributes from the original file's FileInfo

to
> > the new file's FileInfo and that would update the actual file, thus

>
> This will work. It was only a little note because most people forget
> that the creation date may sometimes be useful...
>
> --
> Herfried K. Wagner
> MVP · VB Classic, VB.NET
> <http://www.mvps.org/dotnet>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Text File: Returning To Beginning? PeteCresswell Microsoft Access 1 4th Mar 2009 02:49 PM
Inserting text at the beginning of an existing text file =?Utf-8?B?QUhQ?= Microsoft VB .NET 4 24th Jan 2006 05:54 AM
How to append text to the beginning of the text file Peter Afonin Microsoft Access ADP SQL Server 6 18th Aug 2004 02:41 AM
How to append text to the beginning of the text file Peter Afonin Microsoft Access External Data 6 18th Aug 2004 02:41 AM
How to append text to the beginning of the text file Peter Afonin Microsoft Access 6 18th Aug 2004 02:41 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:51 PM.