【发布时间】:2009-11-07 13:54:29
【问题描述】:
我需要对我的 Visual Basic 2008 程序进行文件搜索。你们知道如何开始吗?我听说您需要管理员权限才能进行某些文件搜索,但我不想要任何此类事情,因为这对用户来说是一个错误。
【问题讨论】:
-
@CodyGray 你说得对,我会很快了解它们。如果签名不占用太多空间,我倾向于保留它们......
我需要对我的 Visual Basic 2008 程序进行文件搜索。你们知道如何开始吗?我听说您需要管理员权限才能进行某些文件搜索,但我不想要任何此类事情,因为这对用户来说是一个错误。
【问题讨论】:
System.IO.Directory Class 应该可以帮助您。
您可能还想构建一个目录系统或寻找一个支持 API 的系统。这样您就不必在每次用户执行查询时遍历目录结构。
基本上你可以做(伪代码,调整以适应):
Dim fn as File
For Each fn in System.IO.Directory.GetFiles(SomePath,"*.*",System.IO.SearchOption.AllDirectories)
' Do something with the fn
End For
现在没有办法绕过 NTFS ACL,您需要适当处理。
看看这篇文章,从 C# 中挂钩到 Windows Desktop Search。
Microsoft Windows Search 3.x SDK
简要说明
1.0 版
下载 Windows 搜索软件 开发套件探索样本 应用程序和使用 Visual 进行开发 Studio、C# 和 .NET 技术。
更新 1
对目录中的文件进行处理的函数(伪代码,调整以适应):
Public Function MyDirectoryFunction(ByVal dir as String, ByVal fileMatch as String, ByVal beRecursive as Boolean)
Dim fn as File
Dim searchOpt as System.IO.SearchOption
If beRecursive = True Then
searchOpt = System.IO.SearchOption.AllDirectories
Else
searchOpt = System.IO.SearchOption.TopDirectoryOnly
End If
If String.IsNullOrEmpty(fileMatch) Then
fileMatch = "*.*"
End If
For Each fn in System.IO.Directory.GetFiles(dir, fileMatch, searchOpt)
' Do something with the fn
End For
End Function
【讨论】: