テキストファイルの「X」行以降のすべての行を削除しようとしています。最初の「X」行を保持し、残りの行を削除することを意味します。
私はこの方法でこれを行う方法を知っています:
1. Open the textfile
2. Read line by line
3. Count the line number.
4. Store the line content and append the string in the new textfile
5. Continue reading the next line and doing the same (step 3 & 4).
6. When line-count reaches "X" then stop reading lines.
これを行うにはあまりにも多くの手順と遅い方法があります。テキストファイルの最初の 1.000 行を保持し、残りの行を削除するためのより良い (高速) 方法を誰かが知っていますか?
Private Sub Resize_LogFile()
If File.ReadAllLines(LogFile).Length > 1000 Then
' Delete all the lines after line number: 1.000
' Save it
End If
End Sub