Results 1 to 5 of 5

Thread: VB - FindFiles

  1. #1

    Thread Starter
    Frenzied Member ice_531's Avatar
    Join Date
    Aug 2002
    Location
    Sitting w/ Bob Status: -Next -To- Null- Friend: Philip
    Posts
    1,152

    VB - FindFiles

    Well i've noticed theres been alot of talk in threads on the findfirstfile and findnextfile apis used to search a directory based on filename or partial filename/extension.

    One problem is it seems to take quite awhile to go through all the subdirectories and files...it can take a few minutes worth of time.

    like to see if anyone has any approaches to this that is speedy and convienent (sp)


    :::`DISCLAIMER`:::
    Do NOT take anything i have posted to be truthful in any way, shape or form.
    Thank You!

    --------------------------------
    "Never heard about "hiking" poles. I usualy just grab a stick from the nature, and use that as a pole." - NoteMe
    "Finaly I can look as gay as I want..." - NoteMe
    Languages: VB6, BASIC, Java, C#. C++

  2. #2
    Hyperactive Member Maven's Avatar
    Join Date
    Feb 2003
    Location
    Greeneville, TN
    Posts
    322

    Re: VB - FindFiles

    Pretty much when you deal with api's, there is not much you can do to optimize things that an API does because all of that code is hidden from you. On another note if you search an entire hard drive for something, then it will take some time and there is no way around that.
    Education is an admirable thing, but it is well to remember from time to time that nothing that is worth knowing can be taught. - Oscar Wilde

  3. #3

    Thread Starter
    Frenzied Member ice_531's Avatar
    Join Date
    Aug 2002
    Location
    Sitting w/ Bob Status: -Next -To- Null- Friend: Philip
    Posts
    1,152

    Re: VB - FindFiles

    True. However i am dealing with just 1 directory , not the entire drive.

    for instance: the desktop
    i did a test and timed it.. went through around 1200 files and took like 50 seconds

    just to find 5 files. That is too slow! i want something that will be finished within a 20 second time period.
    :::`DISCLAIMER`:::
    Do NOT take anything i have posted to be truthful in any way, shape or form.
    Thank You!

    --------------------------------
    "Never heard about "hiking" poles. I usualy just grab a stick from the nature, and use that as a pole." - NoteMe
    "Finaly I can look as gay as I want..." - NoteMe
    Languages: VB6, BASIC, Java, C#. C++

  4. #4
    Hyperactive Member Maven's Avatar
    Join Date
    Feb 2003
    Location
    Greeneville, TN
    Posts
    322

    Re: VB - FindFiles

    Quote Originally Posted by ice_531
    True. However i am dealing with just 1 directory , not the entire drive.

    for instance: the desktop
    i did a test and timed it.. went through around 1200 files and took like 50 seconds

    just to find 5 files. That is too slow! i want something that will be finished within a 20 second time period.
    Searching on a hard drive can be slow, a good eaxmple is using search that is built into windows. The reason for this is due a lot to hardware (Access time, bandwdith, etc). It's pretty much the reason why we have memory and hard drives instead of just hard drives....

    Display your code anyway, so I can see what your doing.
    Education is an admirable thing, but it is well to remember from time to time that nothing that is worth knowing can be taught. - Oscar Wilde

  5. #5
    Fanatic Member
    Join Date
    Sep 2000
    Posts
    770

    Lightbulb Re: VB - FindFiles

    Ok this is a long winded explanation on how to speed up your directory searches, so please, bare with me....

    1.)

    Setup an Access database and have your program index files from a target directory into the database.

    Example database table layout
    ----------------
    IndexID - Autonumber, Auto-incrementing field (primary key)
    FileName - Filename of the file, minus the file's extension
    FileExtension - Extension of file, minus the leading period
    FileSize - Size of file, in bytes
    Hash - 32 byte digest of file (THIS MUST BE SET AS A UNIQUE INDEX)
    DateIndexed - Date that this index for this was generated

    NOTE: The field Hash is a simple 32 byte MD5 digest of the target file to be indexed. THIS IS VERY IMPORTANT!!!! You dont want do keep inserting duplicates of the same old file, you want your program to add only new files that have not been previously indexed.

    2.)

    Create a function that will scan the directory and retrive the following information outlined above and store it in the database. WATCHOUT!!! You can use the same function to also re-scan a directory BUT when your function tries to add a record with info from a file it has already indexed e.g. same md5 hash, ADO will give you an error when you try to insert, you need to catch the error and just move to the next file to be indexed. You could write a seprate function to first check to see if a file has been indexed, but that is slower and takes more coding time on your part.


    3.)

    Now you can run blazing fast searches on that info using SQL, e.g.

    SELECT FileName, FileExtension, FileSize FROM table WHERE FileName = '%resume%' AND FileExtension = 'doc' ORDER BY FileName ASC

    NOTE: Disregard the backslashes, the forum adds those. Grr.

    But see where I am going with this? With that SQL statement you can run very fast searches based on parts of a filename matched with given extension. Of course this is just an example and you could create many different types of queries to meet your needs.

    4. )

    You can get an MD5 component thats freely available for download at http://xstandard.com/download.asp




    Well, I hope this is not too complicated for you. But it WILL solve your problems. Let me know if this helped.
    Last edited by nkad; Dec 22nd, 2004 at 03:48 PM.

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