Results 1 to 7 of 7
  1. #1
    Bombsaway707's Avatar
    Join Date
    Jun 2009
    Gender
    male
    Location
    Gym
    Posts
    8,799
    Reputation
    791
    Thanks
    4,004
    My Mood
    Amused

    How to filter search results

    Ok so im using the following code to find subfolders in a folder:
    Code:
     Private Sub DirSearch(ByVal sDir As String)
            Application.DoEvents()
            For Each d As String In Directory.GetDirectories(sDir)
                Console.WriteLine(d)
                DirSearch(d)
                ListBox1.Items.Add(d)
                Timer1.Start()
            Next
        End Sub
    I was just wondering how i would filter the search results to remove all folders containing the word itunes, windows ect. this is for my file scanner which i dont want to scan in places i know recent files won't be. Also i'm dealing with literally tens of thousands of folders so filtering out windows folders would reduce a lot of unnecessary scanning.
    Thanks
    Last edited by Bombsaway707; 11-30-2010 at 06:14 PM.

  2. #2
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Quote Originally Posted by Bombsaway707 View Post
    Ok so im using the following code to find subfolders in a folder:
    Code:
     Private Sub DirSearch(ByVal sDir As String)
            Application.DoEvents()
            For Each d As String In Directory.GetDirectories(sDir)
                Console.WriteLine(d)
                DirSearch(d)
                ListBox1.Items.Add(d)
                Timer1.Start()
            Next
        End Sub
    I was just wondering how i would filter the search results to remove all folders containing the word itunes, windows ect. this is for my file scanner which i dont want to scan in places i know recent files won't be. Also i'm dealing with literally tens of thousands of folders so filtering out windows folders would reduce a lot of unnecessary scanning.
    Thanks
    Code:
     Private Sub DirSearch(ByVal sDir As String)
            Application.DoEvents()
            For Each d As String In Directory.GetDirectories(sDir)
    If d.contains("iTunes") or d.Contains("Windows") Then
    Continue For
    End If
               Console.WriteLine(d)
                DirSearch(d)
                ListBox1.Items.Add(d)
                Timer1.Start()
            Next
    End Sub

  3. #3
    freedompeace's Avatar
    Join Date
    Jul 2010
    Gender
    female
    Posts
    3,033
    Reputation
    340
    Thanks
    2,792
    My Mood
    Sad
    Code:
     Private Sub DirSearch(ByVal sDir As String)
            Application.DoEvents()
            For Each d As String In Directory.GetDirectories(sDir)
                If d.ToLower.Contains("itunes") Or d.ToLower.Contains("windows") Then
                            Continue For
                End If
                Console.WriteLine(d)
                DirSearch(d)
                ListBox1.Items.Add(d)
                Timer1.Start()
            Next
    End Sub
    By the way, why'd you leave the random Console.WriteLine in there? <.<

    And I'll just point out that starting the timer every time the for loops occurs may be unnecessary (depending on what your code does).

  4. #4
    Bombsaway707's Avatar
    Join Date
    Jun 2009
    Gender
    male
    Location
    Gym
    Posts
    8,799
    Reputation
    791
    Thanks
    4,004
    My Mood
    Amused
    Quote Originally Posted by freedompeace View Post
    Code:
     Private Sub DirSearch(ByVal sDir As String)
            Application.DoEvents()
            For Each d As String In Directory.GetDirectories(sDir)
                If d.ToLower.Contains("itunes") Or d.ToLower.Contains("windows") Then
                            Continue For
                End If
                Console.WriteLine(d)
                DirSearch(d)
                ListBox1.Items.Add(d)
                Timer1.Start()
            Next
    End Sub
    By the way, why'd you leave the random Console.WriteLine in there? <.<

    And I'll just point out that starting the timer every time the for loops occurs may be unnecessary (depending on what your code does).
    I just C&P what u wrote in their and i didnt take anything out cuz tbh i wasn't sure what it all did as im not really familiar with folder scanning. And the timer scans the folders that are found for files

  5. #5
    freedompeace's Avatar
    Join Date
    Jul 2010
    Gender
    female
    Posts
    3,033
    Reputation
    340
    Thanks
    2,792
    My Mood
    Sad
    Quote Originally Posted by Bombsaway707 View Post

    I just C&P what u wrote in their and i didnt take anything out cuz tbh i wasn't sure what it all did as im not really familiar with folder scanning. And the timer scans the folders that are found for files
    Okay. So what you want to do is remove BOTH

    Console.WriteLine
    Timer1.Start

    And then delete your timer - you wont need t altogether.

    Now just call DirSearch(...) at your form's Load event or allow the user toc click a button to start it (on the click event)

    So like

    Private Function Form1_Load(ByVal ... ' provided already by the load function
    DirSearch("C:\freedompeace")
    End Function

    Or something in a button.

    I would show you how to multithread it, but typing on my mobile is way hard <.<

  6. #6
    Bombsaway707's Avatar
    Join Date
    Jun 2009
    Gender
    male
    Location
    Gym
    Posts
    8,799
    Reputation
    791
    Thanks
    4,004
    My Mood
    Amused
    Quote Originally Posted by freedompeace View Post
    Okay. So what you want to do is remove BOTH

    Console.WriteLine
    Timer1.Start

    And then delete your timer - you wont need t altogether.

    Now just call DirSearch(...) at your form's Load event or allow the user toc click a button to start it (on the click event)

    So like

    Private Function Form1_Load(ByVal ... ' provided already by the load function
    DirSearch("C:\freedompeace")
    End Function

    Or something in a button.

    I would show you how to multithread it, but typing on my mobile is way hard <.<
    Well see the timer contains a code which scans all the folders found using the previous code for files. Like it takes all the folders found and then proceeds to scan them for files so im pretty sure its needed

  7. #7
    freedompeace's Avatar
    Join Date
    Jul 2010
    Gender
    female
    Posts
    3,033
    Reputation
    340
    Thanks
    2,792
    My Mood
    Sad
    Quote Originally Posted by Bombsaway707 View Post

    Well see the timer contains a code which scans all the folders found using the previous code for files. Like it takes all the folders found and then proceeds to scan them for files so im pretty sure its needed
    Well you see, in that case, it might be better to do it in the same loop. Iterating through folders takes a mere few milliseconds. It wouldn't be too bad to search for files while you're in there as well.