VB查找硬盘文件(全硬搜索)
来源:互联网 发布:最差的985东北大学知乎 编辑:程序博客网 时间:2024/05/16 11:24
Private Declare Function SearchTreeForFile Lib "imagehlp.dll" (ByVal lpRoothPath As String, ByVal lpInputName As String, ByVal lpOutputName As String) As Long
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Public Function getDirList() As String() '得到硬盘列表,下标0开始
Dim tmp As String * 64
GetLogicalDriveStrings Len(tmp), tmp '得到所有外存盘符列表
dirlist = Split(tmp, Chr(0))
Dim Count As Integer
Count = 0
Dim arr() As String
For i = 0 To UBound(dirlist)
Select Case GetDriveType(dirlist(i))
Case 2 'Removable
Case 3 'Drive Fixed
ReDim Preserve arr(Count) As String
arr(Count) = dirlist(i)
Count = Count + 1
Case 4 'Remote
Case 5 'CD-ROM
Case 6 'RAM Disk
Case Else 'Unrecognized
End Select
Next
getDirList = arr
End Function
Public Function sysFileFind(ByVal WhichRootPath As String, ByVal WhichFileName As String) As String
Dim iNull As Integer
Dim lResult As Long
Dim sBuffer As String
On Error GoTo L_FILEFINDERROR
sBuffer = String$(1024, 0)
'注释:查找文件
lResult = SearchTreeForFile(WhichRootPath, WhichFileName, sBuffer)
'注释:如果文件找到,将返回字符串后续的空格删除
'注释:否则返回一个空字符串
If lResult Then
iNull = InStr(sBuffer, vbNullChar)
If Not iNull Then
sBuffer = Left$(sBuffer, iNull - 1)
End If
sysFileFind = sBuffer
Else
sysFileFind = ""
End If
Exit Function
L_FILEFINDERROR:
MsgBox "查找文件过程中遇到错误!", vbInformation, "查找文件错误", sysFileFind = Format(Err.Number) & " - " & Err.Description
End Function
Function allSearch(FileName As String) As String
arr = getDirList() '得到硬盘列表
allSearch = ""
For i = 0 To UBound(arr)
allSearch = sysFileFind(arr(i), FileName)
If Len(allSearch) > 0 Then
Exit For
End If
Next
End Function
Private Sub Command1_Click()
Print allSearch("PS7.reg") '查找文件PS7.reg
End Sub
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Public Function getDirList() As String() '得到硬盘列表,下标0开始
Dim tmp As String * 64
GetLogicalDriveStrings Len(tmp), tmp '得到所有外存盘符列表
dirlist = Split(tmp, Chr(0))
Dim Count As Integer
Count = 0
Dim arr() As String
For i = 0 To UBound(dirlist)
Select Case GetDriveType(dirlist(i))
Case 2 'Removable
Case 3 'Drive Fixed
ReDim Preserve arr(Count) As String
arr(Count) = dirlist(i)
Count = Count + 1
Case 4 'Remote
Case 5 'CD-ROM
Case 6 'RAM Disk
Case Else 'Unrecognized
End Select
Next
getDirList = arr
End Function
Public Function sysFileFind(ByVal WhichRootPath As String, ByVal WhichFileName As String) As String
Dim iNull As Integer
Dim lResult As Long
Dim sBuffer As String
On Error GoTo L_FILEFINDERROR
sBuffer = String$(1024, 0)
'注释:查找文件
lResult = SearchTreeForFile(WhichRootPath, WhichFileName, sBuffer)
'注释:如果文件找到,将返回字符串后续的空格删除
'注释:否则返回一个空字符串
If lResult Then
iNull = InStr(sBuffer, vbNullChar)
If Not iNull Then
sBuffer = Left$(sBuffer, iNull - 1)
End If
sysFileFind = sBuffer
Else
sysFileFind = ""
End If
Exit Function
L_FILEFINDERROR:
MsgBox "查找文件过程中遇到错误!", vbInformation, "查找文件错误", sysFileFind = Format(Err.Number) & " - " & Err.Description
End Function
Function allSearch(FileName As String) As String
arr = getDirList() '得到硬盘列表
allSearch = ""
For i = 0 To UBound(arr)
allSearch = sysFileFind(arr(i), FileName)
If Len(allSearch) > 0 Then
Exit For
End If
Next
End Function
Private Sub Command1_Click()
Print allSearch("PS7.reg") '查找文件PS7.reg
End Sub
- VB查找硬盘文件(全硬搜索)
- 全硬盘高速查找指定文件
- 硬盘文件搜索代码(ASP类)
- 很好用的全硬盘搜索工具
- C#实现硬盘文件搜索
- 搜索硬盘下目录文件
- Linux文件搜索查找
- Linux文件搜索查找
- Linux文件搜索查找
- linux 查找搜索文件
- 搜索项目中指定文件夹下的文件(VB)
- linux文件搜索查找命令
- linux文件搜索查找命令
- linux文件搜索查找命令
- linux文件搜索查找命令
- 对硬盘文件进行二分查找
- Python:查找硬盘上重复文件
- 一个硬盘文件搜索的Asp源码
- 深入理解REST(二)
- Oracle基础--体系结构
- Linux下FTP命令行使用精萃(转)
- ORA-01194
- apache 压力测试工具
- VB查找硬盘文件(全硬搜索)
- Win2k3+Solaris+FreeBSD+Linux 疯狂装记
- sz/rz命令解析(转)
- 用户如何有效地利用数据字典
- Lilybbs.LinuxUnix.iFAQ
- 常用正则表达式集锦
- Oracle基础--性能配置
- 通过url传递大数据
- 最近有点苦