Results 1 to 4 of 4

Thread: Searching for a specific file and save the path

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2002
    Posts
    665

    Question Searching for a specific file and save the path

    I want to scan a drive (d:\ etc.) for a particular filename. In each folder I find the file I'm looking for, I want to copy the full path from the root and save it to a text file or in a table in Access.
    Ex: D:\folder1\folder2\folder3

    I do not know what to do, someone who can help me?
    Last edited by Pirre001; Mar 3rd, 2014 at 03:27 PM.

  2. #2
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    750

    Re: Searching for a specific file and save the path

    You probably need a recursive search. I hate recursion; my brain is too small to follow the logic but it's often a necessary evil ;-)

    Try this:

    http://support.microsoft.com/kb/306666

    It's a little old but should still be valid. This bit of code probably does all you need:

    Code:
    Sub DirSearch(ByVal sDir As String)
            Dim d As String
            Dim f As String
    
            Try
                For Each d In Directory.GetDirectories(sDir)
                    For Each f In Directory.GetFiles(d, txtFile.Text)
                        lstFilesFound.Items.Add(f)
                    Next
                    DirSearch(d)
                Next
            Catch excpt As System.Exception
                Debug.WriteLine(excpt.Message)
            End Try
        End Sub

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2002
    Posts
    665

    Re: Searching for a specific file and save the path

    Thank you. Yes, it may not be needed more code.

    A follow-up question... if I caches up this and also retrieves data from a table in a database that also contains a path and cashing it also. How can I easily compare these two who match each other? Using me of linq? If so, how?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Searching for a specific file and save the path

    Quote Originally Posted by Pirre001 View Post
    Thank you. Yes, it may not be needed more code.

    A follow-up question... if I caches up this and also retrieves data from a table in a database that also contains a path and cashing it also. How can I easily compare these two who match each other? Using me of linq? If so, how?
    It's not clear what you're asking for. Are you saying that you have two lists of file paths and you want to find those that in both lists? In one list and not the other? Something else? Please be CLEAR and SPECIFIC.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width