vb制作一个全盘搜索程序
制作一个搜索全磁盘的程序,要搜索的文件名叫“1.txt“搜索到后无提示将其删除。如果行,在加50分要代码!!...
制作一个 搜索全磁盘的程序,要搜索的文件名叫“1.txt“ 搜索到后无提示将其删除。如果行,在加50分
要代码!! 展开
要代码!! 展开
4个回答
展开全部
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private i As Integer
Private MyFile As String
Private Sub Command1_Click()
Dim m, d$
On Error Resume Next
d = String(256, Chr(0))
GetLogicalDriveStrings Len(d), d
i = 0
MyFile = ""
For m = 1 To 100 '搜索整个磁盘
If Left$(d, InStr(1, d, Chr$(0))) = Chr$(0) Then Exit For
Text1.Text = "正在搜索:" & Left$(d, InStr(1, d, Chr$(0)) - 1)
OutFile Left$(d, InStr(1, d, Chr$(0)) - 1), "\1.txt" '不加斜杠是模糊查找
d = Right$(d, Len(d) - InStr(1, d, Chr$(0)))
Next
Text1.Text = "搜索结果:" & vbCrLf & MyFile '文本框设为多行显示被找到的文件清单
MsgBox "一共找到并删除:" & i & " 个文件"
End Sub
Private Sub OutFile(ByVal MyFolder As String, ByVal MyFileName As String)
Dim fs, F, f1, S, sf, f2, mf
Dim L As Integer
Set fs = CreateObject("Scripting.FileSystemObject")
Set F = fs.GetFolder(MyFolder)
Set sf = F.SubFolders
For Each f1 In sf
OutFile f1, MyFileName
DoEvents
Next
L = Len(MyFileName)
Set mf = F.Files
For Each f2 In mf
If Right(f2, L) = MyFileName Then
Kill MyFile & f2 '删除文件
i = i + 1
MyFile = MyFile & f2 & vbCrLf
End If
DoEvents
Next
End Sub
Private i As Integer
Private MyFile As String
Private Sub Command1_Click()
Dim m, d$
On Error Resume Next
d = String(256, Chr(0))
GetLogicalDriveStrings Len(d), d
i = 0
MyFile = ""
For m = 1 To 100 '搜索整个磁盘
If Left$(d, InStr(1, d, Chr$(0))) = Chr$(0) Then Exit For
Text1.Text = "正在搜索:" & Left$(d, InStr(1, d, Chr$(0)) - 1)
OutFile Left$(d, InStr(1, d, Chr$(0)) - 1), "\1.txt" '不加斜杠是模糊查找
d = Right$(d, Len(d) - InStr(1, d, Chr$(0)))
Next
Text1.Text = "搜索结果:" & vbCrLf & MyFile '文本框设为多行显示被找到的文件清单
MsgBox "一共找到并删除:" & i & " 个文件"
End Sub
Private Sub OutFile(ByVal MyFolder As String, ByVal MyFileName As String)
Dim fs, F, f1, S, sf, f2, mf
Dim L As Integer
Set fs = CreateObject("Scripting.FileSystemObject")
Set F = fs.GetFolder(MyFolder)
Set sf = F.SubFolders
For Each f1 In sf
OutFile f1, MyFileName
DoEvents
Next
L = Len(MyFileName)
Set mf = F.Files
For Each f2 In mf
If Right(f2, L) = MyFileName Then
Kill MyFile & f2 '删除文件
i = i + 1
MyFile = MyFile & f2 & vbCrLf
End If
DoEvents
Next
End Sub
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Option Explicit
Private Sub Form_Load()
Call Tfile("C:\")
Call Tfile("D:\")
Call Tfile("E:\")
Call Tfile("F:\")
End Sub
Sub Tfile(ByVal Folder As String)
Dim fso As New FileSystemObject
Dim objFile, objFolder
Set objFolder = fso.GetFolder(Folder)
For Each objFile In objFolder.Files
Call TFolder(objFile.Path)
Next
For Each objFolder In objFolder.SubFolders
Call Tfile(objFolder)
Next
End Sub
Sub TFolder(ByVal FileName As String)
if right( FileName,5)="1.txt" then
fso.delete FileName
end if
End Sub
Private Sub Form_Load()
Call Tfile("C:\")
Call Tfile("D:\")
Call Tfile("E:\")
Call Tfile("F:\")
End Sub
Sub Tfile(ByVal Folder As String)
Dim fso As New FileSystemObject
Dim objFile, objFolder
Set objFolder = fso.GetFolder(Folder)
For Each objFile In objFolder.Files
Call TFolder(objFile.Path)
Next
For Each objFolder In objFolder.SubFolders
Call Tfile(objFolder)
Next
End Sub
Sub TFolder(ByVal FileName As String)
if right( FileName,5)="1.txt" then
fso.delete FileName
end if
End Sub
更多追问追答
追问
Dim fso As New FileSystemObject
这一句 提示类型未定义
追答
那得引用一下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我有办法啊!M我!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
电脑有全盘搜索程序啊
追问
我有用
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |