请问用vb怎么实现在未知路径上搜索扩展名为*.ico的文件,并且把搜索到的文件删除掉?
答案:1 悬赏:40 手机版
解决时间 2021-01-30 06:49
- 提问者网友:你挡着我发光了
- 2021-01-29 10:06
请问用vb怎么实现在未知路径上搜索扩展名为*.ico的文件,并且把搜索到的文件删除掉?
最佳答案
- 五星知识达人网友:举杯邀酒敬孤独
- 2020-12-10 11:09
以下代码可删除d盘中所有扩展名为*.ico的文件。如果要删除所有硬盘分区中的指定文件,你可以遍历所有分区盘符:
Private Sub Command1_Click()
ss "d:"
End Sub
Sub ss(d As String)
Dim dd As String, ds() As String, i As Integer, s As Integer
dd = Dir(d & "\", vbNormal + vbDirectory)
Do Until dd = ""
If dd <> "." And dd <> ".." Then
If (GetAttr(d & "\" & dd) And vbDirectory) = vbDirectory Then
s = s + 1
ReDim Preserve ds(1 To s)
ds(s) = d & "\" & dd
Else
If LCase(Right(dd, 4)) = ".ico" Then Kill d & "\" & dd
End If
End If
dd = Dir
Loop
For i = 1 To s
ss ds(i)
Next
End Sub
Private Sub Command1_Click()
ss "d:"
End Sub
Sub ss(d As String)
Dim dd As String, ds() As String, i As Integer, s As Integer
dd = Dir(d & "\", vbNormal + vbDirectory)
Do Until dd = ""
If dd <> "." And dd <> ".." Then
If (GetAttr(d & "\" & dd) And vbDirectory) = vbDirectory Then
s = s + 1
ReDim Preserve ds(1 To s)
ds(s) = d & "\" & dd
Else
If LCase(Right(dd, 4)) = ".ico" Then Kill d & "\" & dd
End If
End If
dd = Dir
Loop
For i = 1 To s
ss ds(i)
Next
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯