none
Can a vb program search the contents of files (like Windows' search feature can do)? RRS feed

  • Question

  • Is there a simple way to do such a search, rather than using the Windows API. If not, then how do you use the API do to it?

    Robert Homes

    Tuesday, October 10, 2017 9:09 AM

Answers

  • Have you tried FindInFiles.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Robert Homes Tuesday, October 10, 2017 10:15 AM
    Tuesday, October 10, 2017 10:11 AM
    Moderator
  • Glad to be of assistance. A couple of thoughts, if you might be attempting to access folder that you or the user does not have proper permissions to then wrap you code in a try-catch.

    If you are searching a lot of folders/files consider using asynchronous  task e.g.

    Imports System.Collections.ObjectModel
    Imports Microsoft.VisualBasic.FileIO
    Public Class Form1
        Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim results As ReadOnlyCollection(Of String) = Nothing
            Await Task.Run(
                Sub()
                    results = FileSystem.FindInFiles("C:\VS2015", "await", True,
                                                     SearchOption.SearchAllSubDirectories)
                End Sub)
    
            For Each item In results
                Console.WriteLine(item)
            Next
        End Sub
    End Class
    This will keep your app responsive.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Robert Homes Tuesday, October 10, 2017 6:19 PM
    Tuesday, October 10, 2017 11:14 AM
    Moderator

All replies

  • Have you tried FindInFiles.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Robert Homes Tuesday, October 10, 2017 10:15 AM
    Tuesday, October 10, 2017 10:11 AM
    Moderator
  • No, I haven't tried it, didn't know about it! Thanks so much.

    Robert Homes

    Tuesday, October 10, 2017 10:15 AM
  • Glad to be of assistance. A couple of thoughts, if you might be attempting to access folder that you or the user does not have proper permissions to then wrap you code in a try-catch.

    If you are searching a lot of folders/files consider using asynchronous  task e.g.

    Imports System.Collections.ObjectModel
    Imports Microsoft.VisualBasic.FileIO
    Public Class Form1
        Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim results As ReadOnlyCollection(Of String) = Nothing
            Await Task.Run(
                Sub()
                    results = FileSystem.FindInFiles("C:\VS2015", "await", True,
                                                     SearchOption.SearchAllSubDirectories)
                End Sub)
    
            For Each item In results
                Console.WriteLine(item)
            Next
        End Sub
    End Class
    This will keep your app responsive.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Robert Homes Tuesday, October 10, 2017 6:19 PM
    Tuesday, October 10, 2017 11:14 AM
    Moderator
  • Karen,

    Thank you again! I wish I could tell you how much I appreciate the help I get from you and other VB experts on your site. It is just great.


    Robert Homes

    Tuesday, October 10, 2017 6:21 PM