2012-10-23 46 views
1

是否有api在文檔(.txt,.doc,.xls,pdf)上執行本地內容文件搜索?Windows桌面搜索vb .net

我還沒有嘗試過,但搜索谷歌桌面搜索API已被棄用,Windows桌面搜索,因爲我已閱讀只有確切的搜索,我不知道這是否是一箇舊產品。

Copernic桌面搜索是一個獨立的程序,我不尋找這樣的事情。

這種搜索是否有一些解決方案?

回答

1

我不太清楚你在找什麼,但這樣的事情會工作...

Dim theFiles As New Collections.Generic.Dictionary(Of String, String) 
    Dim extensions() As String = {".doc", ".docx", ".txt", ".xls", ".xlsm", ".docm", ".cpp", ".h", ".pdf", ".pps", "pptm", ".odt", ".rtf", "wpd", ".wps", ".ppt", ".pptx"} 
    Dim directoriesToSearch As New ArrayList 
    directoriesToSearch.AddRange({Environment.SpecialFolder.Personal.ToString,           Environment.SpecialFolder.Recent.ToString, Environment.SpecialFolder.Favorites.ToString, _ 
           My.Computer.FileSystem.SpecialDirectories.Desktop.ToString, My.Computer.FileSystem.SpecialDirectories.MyDocuments}) 
    Dim thing As String 
    For Each drive In DriveInfo.GetDrives 
     If Not drive.Name = "C:\" And directoriesToSearch.Contains(drive) = False Then 
      If drive.IsReady = True Then 
       If drive.DriveFormat = "NTFS" Or drive.DriveFormat = "FAT32" Then 
        directoriesToSearch.Add(drive.Name) 
       End If 
      End If 
     End If 
    Next 
    theFiles.Clear() 
    For Each thing In directoriesToSearch 
     If Directory.Exists(thing) = True Then 
      For Each doc In Directory.EnumerateFiles(thing) 
       For Each ext In extensions 
        If Path.GetExtension(doc) = ext And Path.GetFileNameWithoutExtension(doc).StartsWith("~") = False Then 
         Dim newFile As RecentFiles 
         If theFiles.ContainsValue(Path.GetFileNameWithoutExtension(doc)) = False Then 
          newFile.theName = Path.GetFileNameWithoutExtension(doc) 
          newFile.thePath = Path.GetFullPath(doc) 
          theFiles.Add(newFile.thePath, newFile.theName) 
         End If 
        End If 
       Next 
      Next 
     End If 
    Next 
    Return theFiles 

我檢查,如果他們有任何外部驅動器,但你不要有太多。哦,它是多餘的做...

 newFile.theName = Path.GetFileNameWithoutExtension(doc) 
     newFile.thePath = Path.GetFullPath(doc) 

theFiles.Add(newFile.thePath,newFile.theName)

我試圖在東西張貼這是前兩行了,只是實現完全沒有必要。