Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How To Control The Size Of A File??

Posted on 2004-08-05
4
Medium Priority
?
236 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 250 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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…

877 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