Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How To Control The Size Of A File??

Posted on 2004-08-05
4
Medium Priority
?
234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This is about my first experience with programming Arduino.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
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 …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

719 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