0

Greetings,

I am keeping a log of the amount of time a machine has run.

I have a textfile with timestamps and the amount of minutes my machine has run.

To keep the size of the file in check, I would like to delete the first half of the text file, once the textfile exceeds 1 MB... I have a check in place to determine the file size.

What is the best way to go about deleting the first half of my textfile log?

Do you recommend storing the second half in a temp file, and transfering it to the original log?

Is there a simple way to remove the first few lines of a textfile?

Thank you for the advice! Hardware guy, learning VB. Take care

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by thines01
1

If your file is based on line-count, you can quickly count the lines and decide how many to keep. On the second pass, capture the last x-number of lines and write them to a temp file (or store in an aray). Close the original file then OVERWRITE it with the data from the array or delete the file and rename the temp file to the log file name.

And yes, at first, this is uglier than you think it should be.

Edited by thines01: typo

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.