Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Searching for files using vb.net 2005

Searching for files using vb.net 2005

Scheduled Pinned Locked Moved Visual Basic
csharpalgorithmsdebugginghelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mitsroff
    wrote on last edited by
    #1

    I stole this snippet from a C# forum and converted it into VB. It's a routine for searching files recursively. When i test it however, I get the "Access to the path 'C:\System Volume Information' is denied." error. I've tried the old VB6: On Error Resume Next. Doesn't work thou. Any way to get around it? Private Sub DirSearch(ByVal sDir As String) Dim arrLst As New ArrayList Dim _dir As String Dim _file As String Try For Each _dir In Directory.GetDirectories(sDir) For Each _file In Directory.GetFiles(_dir, txtFile.Text) arrLst.Add(_file) Next DirSearch(_dir) Next Catch ex As Exception Debug.Print(ex.Message) End Try End Sub Thanks

    C Y 2 Replies Last reply
    0
    • M mitsroff

      I stole this snippet from a C# forum and converted it into VB. It's a routine for searching files recursively. When i test it however, I get the "Access to the path 'C:\System Volume Information' is denied." error. I've tried the old VB6: On Error Resume Next. Doesn't work thou. Any way to get around it? Private Sub DirSearch(ByVal sDir As String) Dim arrLst As New ArrayList Dim _dir As String Dim _file As String Try For Each _dir In Directory.GetDirectories(sDir) For Each _file In Directory.GetFiles(_dir, txtFile.Text) arrLst.Add(_file) Next DirSearch(_dir) Next Catch ex As Exception Debug.Print(ex.Message) End Try End Sub Thanks

      C Offline
      C Offline
      CWIZO
      wrote on last edited by
      #2

      Add some try/catch block to your code and handle the exception. -------------------------------------------------------- My portfolio & development blog Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!

      1 Reply Last reply
      0
      • M mitsroff

        I stole this snippet from a C# forum and converted it into VB. It's a routine for searching files recursively. When i test it however, I get the "Access to the path 'C:\System Volume Information' is denied." error. I've tried the old VB6: On Error Resume Next. Doesn't work thou. Any way to get around it? Private Sub DirSearch(ByVal sDir As String) Dim arrLst As New ArrayList Dim _dir As String Dim _file As String Try For Each _dir In Directory.GetDirectories(sDir) For Each _file In Directory.GetFiles(_dir, txtFile.Text) arrLst.Add(_file) Next DirSearch(_dir) Next Catch ex As Exception Debug.Print(ex.Message) End Try End Sub Thanks

        Y Offline
        Y Offline
        Yuvi Panda
        wrote on last edited by
        #3

        Well, that's because you don't have enough permission to access that directory. You can just ignore that by moving the Try Block inside the loop, like this :

        Private Sub DirSearch(ByVal sDir As String)

        Dim arrLst As New ArrayList
        Dim _dir As String
        Dim _file As String

        For Each _dir In Directory.GetDirectories(sDir)
        Try
        For Each _file In Directory.GetFiles(_dir, txtFile.Text)
        Try
        arrLst.Add(_file)
        Catch ex as IOException
        Continue
        End Catch
        Next
        DirSearch(_dir)
        Catch ex as IOException
        Continue
        End Try
        Next

        End Sub

        That should fix it. The Continue statements continue the loop into the next iteration, so that exception should be ignored.. Yuvi Panda T 15 year old Microsoft Student Partner Blogs at : http://yuvipanda.blogspot.com

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups