VB 删除txt文件的最后一行
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VB 删除txt文件的最后一行相关的知识,希望对你有一定的参考价值。
Private Sub Command1_Click()
DelTxt App.Path & "\1.txt"
End Sub
Sub DelTxt(ByVal Path As String) ‘删除txt文件的最后一行
On Error GoTo eHandler:
Dim Fc As String, Fn() As String, I As Integer, Wjh As Integer
Wjh = FreeFile
Open Path For Binary As #Wjh
Fc = Space(LOF(Wjh))
Get #Wjh, , Fc
Close #Wjh
Fn = Split(Fc, vbCrLf)
ReDim Preserve Fn(UBound(Fn) - 1)
If UBound(Fn) <= 0 Then
Open Path For Output As #Wjh
Print vbNullString
Close #Wjh
Else
ReDim Preserve Fn(UBound(Fn) - 1)
Open Path For Output As #Wjh
For I = 0 To UBound(Fn)
Print #Wjh, Fn(I)
Next
Close #Wjh
End If
Exit Sub
eHandler:
Err.Clear
End Sub
以上是关于VB 删除txt文件的最后一行的主要内容,如果未能解决你的问题,请参考以下文章