Solved

How To Control The Size Of A File??

Posted on 2004-08-05
4
230 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

685 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