Results 1 to 6 of 6

Thread: Searching Hard Drive For Filenames

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Posts
    108

    Searching Hard Drive For Filenames

    ok, well what im trying to do is write a program that checks in every folder one the hard drive for file names that are contained in a text file. i can probably manage to figure out how to load the file names into an array "name(999999)" but what i want to do is make a loop that checks through each file in every folder on the hard drive to see if the name matches any in the array without being case sensitive. can someone show me how to do this? i would really appreciate it.


    also, if you have some extra time, could you show me an easy way to load the names from the text file which will be in the file like

    file1name
    file2name
    file3name

    and so on, and make each different name go into the array like, the first filename would be contained in name(1) and the second in name(2) etc. Thanks!

  2. #2
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Searching Hard Drive For Filenames

    JayWalker,

    Look here for a project named Scan All Folders on Disk for Files. You can use a collection to store your filenames that you want to search for and test with the collection.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Posts
    108

    Re: Searching Hard Drive For Filenames

    thank you much for the code, i will probably use some code from the scanfolders2 project, since its about 66% faster, but how would i use that code to search for hundreds of individual filenames at a time rather than just an extension, and display the matching paths in a list box?

    im still somewhat inexperienced at vb and i dont know how to use a collection. if you could help it would be great!

  4. #4
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Searching Hard Drive For Filenames

    JayWalker,

    Since the code looks thru each folder, just place code just after it retrieves the filename to check the Array or Collection (I like the latter) for the filename.

    To use a collection:
    VB Code:
    1. Dim colFilenames as Collection
    2. Dim tempFilename as String
    3.  
    4. Set colFilename = New Collection
    5. colFilename.Add Filename,Filename   'Add to the collection. Use the filename as the key and data
    6. ...
    7.  
    8. On Error Resume Next
    9. Set tempName = colFilename.Item(Filename) ' Attempt to retrieve filename from collection. If error occurs, it is not there.
    10.  
    11. If Err.Number = 0 Then   ' No error then do what you need to here
    12. End If
    13.  
    14. On Error GoTo 0

    This was done off the top of my head and may need a tweak or two. But you should get the idea.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Posts
    108

    Re: Searching Hard Drive For Filenames

    sorry, im really new to collections and messing with the hard drive in any way through vb. i dont know where i should put the collection or how to use it because i dont understand where in the code it actually check for a match. i saw how it looks for .vbp file but i dont know how to make it search for a bunch of file names... help please?

  6. #6
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Searching Hard Drive For Filenames

    JayWalker,

    You check for the filename after each call to FindNextFile and FindFirstFile. If you don't understand collections then call a routine that will loop thru the filename you want to search for and check for the filename there.

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