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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.