MsgBox "删除文件:" &DeleteFiles("1.txt", "e:\") &"个" '删除E盘下所有名为1.txt的文件
End Sub
Private Function DeleteFiles(Filename As String, ByVal Path As String) As Integer
Dim D() As String
Dim n As Integer
Dim s As String
Dim i As Integer
If Right(Path, 1) <>"\" Then Path = Path &"\"
n = 1
ReDim D(1 To n)
s = Dir(Path, vbDirectory)
Do
If s = "" Then Exit Do
If (GetAttr(Path &s) And vbDirectory) = vbDirectory And s <>"." And s <>".." Then
D(n) = s
n = n + 1
ReDim Preserve D(1 To n)
End If
s = Dir
Loop
s = Dir(Path &Filename)
If s <>"" Then
Kill Path &Filename
DeleteFiles = DeleteFiles + 1
End If
For i = 1 To UBound(D) - 1
DeleteFiles = DeleteFiles + DeleteFiles(Filename, Path &D(i))
Next i
End Function
分类: 电脑/网络解析:
要是在文本框之类的控件中,不用做,只要不屏蔽BACKSPACE键就会实现删除。要是非要自己做,可以尝试以下方法。
假设记事本中的数据存在strNotepad(string)中
if len(strNotepad>0) then
strNotepad=left(strNotepad,len(strNotepad)-1)
end if
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)