开发者

Visual Basic 2008 File Search

开发者 https://www.devze.com 2022-12-11 06:50 出处:网络
I need a file search for my Visual Basic 2008 program. Do you guys know a way to start off? I\'ve heard that you need admin priveledge for some file searches, but I don\'t want any of those kind of th

I need a file search for my Visual Basic 2008 program. Do you guys know a way to start off? I've heard that you need admin priveledge for some file searches, but I don't want any of those kind of things since it would be a bug to开发者_运维百科 the user.


The System.IO.Directory Class should help you here.

Also you may want to build a catalog system or find a system that supports an API. This way you dont have to walk a directory structure every time the user performs a query.

Basically you can do (pseudo code, adjust to fit):

Dim fn as File

For Each fn in System.IO.Directory.GetFiles(SomePath,"*.*",System.IO.SearchOption.AllDirectories)
  ' Do something with the fn
End For

Now there is no way around the NTFS ACL's and you would need to handle this as appropriate.

Have a look at this post to hook into Windows Desktop Search from C#.

Microsoft Windows Search 3.x SDK

Brief Description

Version 1.0

Download the Windows Search Software Development Kit to explore sample applications and develop using Visual Studio, C#, and .NET technology.

Update 1

Function that does things with files in directories (pseudo code, adjust to fit):

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
0

精彩评论

暂无评论...
验证码 换一张
取 消