VB实现文件的快速搜索问题
Option Explicit
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" _
(ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" _
(ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Private Const INVALID_HANDLE_VALUE = -1
Private Const MaxLFNPath = 260
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MaxLFNPath
cShortFileName As String * 14
End Type
Dim CurPath As String
Dim DirArray() As String
Dim DirCount As Long
Dim FileArray() As String
Dim FileCount As Long
Private Sub Search(CurPath As String, DirArray() As String, DirCount As Long, FileArrary() As String, FileCount As Long)
Dim hItem As Long
Dim WFD As WIN32_FIND_DATA
hItem = FindFirstFile(CurPath & "\*.*", WFD)
If hItem <> INVALID_HANDLE_VALUE Then
Do
If (WFD.dwFileAttributes And vbDirectory) Then
If Asc(WFD.cFileName) <> 46 Then
DirCount = DirCount + 1
ReDim Preserve DirArray(1 To DirCount)
DirArray(DirCount) = CurPath & "\" & Left(WFD.cFileName, InStr(WFD.cFileName, vbNullChar) - 1)
List1.AddItem DirArray(DirCount)
Label1.Caption = DirArray(DirCount)
End If
Else
FileCount = FileCount + 1
ReDim Preserve FileArray(1 To FileCount)
FileArray(FileCount) = CurPath & "\" & Left(WFD.cFileName, InStr(WFD.cFileName, vbNullChar) - 1)
List2.AddItem FileArray(FileCount)
Label2.Caption = FileArray(FileCount)
End If
DoEvents
Loop While FindNextFile(hItem, WFD)
Call FindClose(hItem)
End If
End Sub
Private Sub command1_Click()
CurPath = "c:"
Search CurPath, DirArray(), DirCount, FileArray(), FileCount
Dim i As Long
i = 1
Do While i < DirCount
CurPath = DirArray(i)
Search CurPath, DirArray(), DirCount, FileArray(), FileCount
i = i + 1
Loop
Label1.Caption = "共搜索到" & DirCount & "个文件夹"
Label2.Caption = "共搜索到" & FileCount & "个文件"
End Sub问题:
1,各位高手帮忙看看能够提高一下效率呢?
2,我想以FileArray作为基础数据,比如存入数据库,然后在此基础上进行用户要求的搜索,FileArray的数据结构该如何建立?(还按照现在的数组形式肯定效率低了)
3,想实现对计算机文件的监控,主要监控产生了哪些新文件,哪些文件发生改变了(主要指文件类型),这样能够及时修改第2条中的基础数据,以便能实现用户的搜索要求。
各位帮忙启发下思路吧,谢谢!
相关推荐
VB运用API快速搜索文件
一个小例子,主要是研究运用VB中的API来实现快速搜索文件的功能。
VB实现高效汉字转拼音系统——基于二叉平衡搜索树的完整源码设计
以下是各核心模块及其主要接口定义(VB语法风格):' 汉字处理器接口' 拼音查找引擎End Class' 输出格式化器End Class模块间调用流程如下所示(使用Mermaid流程图表达):graph TDA[用户输入文本] --> B{输入解析模块}B --> C[提取汉字序列]C --> D{拼音查找引擎}D --> E[查询AVL树索引]E --> F[返回拼音数组]F --> G{输出格式化器}G --> H[生成最终结果]H --> I[返回客户端]
VB脚本实现文件名批量重命名技巧
Visual Basic (VB) 是一种简单易学的编程语言,它以事件驱动和快速开发而闻名。VB 通常用于创建Windows应用程序、网站、数据库和其他软件组件。它因其直观的拖放界面和丰富的库支持而成为初学者的理想选择。对象是VBScript和某些Microsoft编程语言中的一个内置对象,属于Windows Script Host的一部分。它提供了一组方法和属性,使得开发者能够对计算机的文件系统进行编程控制。通过,可以执行包括创建、读取、修改、删除文件和文件夹,以及搜索文件系统中的文件等操作。
VB6编程MSDN离线帮助文件大全
MSDN(Microsoft Developer Network)是微软为开发者提供的一个全面的技术资源库,它不仅适用于最新的编程语言和技术,同时也为经典的技术如VB6(Visual Basic 6.0)提供丰富的文档支持。尽管VB6已不再被微软官方推荐使用,但在一些遗留项目中仍然扮演着重要角色。本章节将重点讨论MSDN中与VB6相关的内容,以及如何有效地利用这些资源。
VB源码 快速文件搜索类,并附有VB应用示例
VB源码 快速文件搜索类,并附有VB应用示例


VB基础类
