Solved

How To Control The Size Of A File??

Posted on 2004-08-05
4
226 Views
Last Modified: 2010-04-17
Guru's,

I have a consoleApp written in VB .Net, that writes data to a text file.  What I want to accomplish is this - prior to data being written to the text file - if the file.length is over 4.5MB then we deleted 500 lines from the beginning of the file.
Could someone please show me how to trim or delete 500 lines of data from the beginning of the file in this scenario.

Thank-you

mb
0
Comment
Question by:mebjen
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
joepeg earned 125 total points
ID: 11729913
A character is 1 byte. You could add up the number of characters you wish to write to file, and if it exceeds 4718592 (4.5MB), start writing to file line 501. (You will have essentially 'deleted' 500 lines from your file).

Another option is to write the file (lets call it file A) and check the size as you have already done. If it exceeds 4.5MB, create another file (lets call it B). Open file A, read in 500 lines and ignore them. Copy all additional lines into B. Delete A and rename B to A.

The first option is much more efficient.

.joepeg
0
 

Author Comment

by:mebjen
ID: 11730161
joepeg,

Your first option does indeed seem more efficient - however, the data that gets written to the file is actually appended.  So essentially what I am trying to do is create a file that gets filled from the bottom, and as it grows (when it gets to 4.5MB) data or rows start dropping off or out of the top.

Any thoughts??
0
 
LVL 1

Expert Comment

by:joepeg
ID: 11730449
What is writing the file, and what is accessing the file?
0
 

Author Comment

by:mebjen
ID: 11730638
StreamWriter is writing to it //
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now