Solved

How To Control The Size Of A File??

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Specific format 21 179
firstswap challenge 20 65
C# code editing and collaboration 3 98
MacOS and programming in React 7 27
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
This is about my first experience with programming Arduino.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

932 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

11 Experts available now in Live!

Get 1:1 Help Now