方法有好几种:
1 使用 kill 例如:Kill "c:\temp.txt"
2 使用 FileSystemObject 例如:
Dim FSO As FileSystemObject
Set FSO = New FileSystemObject
FSO.DeleteFile "c:\temp.txt"
1 使用 kill 例如:Kill "c:\temp.txt"
2 使用 FileSystemObject 例如:
Dim FSO As FileSystemObject
Set FSO = New FileSystemObject
FSO.DeleteFile "c:\temp.txt"
filesystemobject
'add reference microsoft scripting runtime into vbDim FsoDel As New FileSystemObject
Private Sub Command2_Click()
Dim i As Long
Dim strFileName As String
Dim j As Integer
j = 0
For i = 28249 To 39196
strFileName = "D:\image\image\" & CStr(i) & "_5.bmp"
Debug.Print strFileName
If FsoDel.FileExists(strFileName) Then
FsoDel.DeleteFile strFileName, True
j = j + 1
End If
Next
MsgBox "共有" & CStr(j) & "图片删除成功"
End Sub