Find A File In Drives Or Folders - 06 Nov 2001

One common task Visual Basic programmers must accomplish is to verify the existence of a specific filename. Most often than not, a simple Dir$ function will suffice - if the path of that filename is known.

Sometimes (in our experience: more times than we care to remember) the path to that file is unknown. Attempting a recursion through the directory structure of today's hard drives, in the attempt to locate that file, is not exactly efficient: you must write a substantial amount of code, and the performance of your best coding effort is always somewhat disappointing.

The code and the sample project we present here demonstrates how to quickly locate a specific filename on a drive.

Assume, for example, that you should verify the existence of the database file "NWIND.MDB". You know that the file could (or should) be stored on drive "C", but you have no knowledge or indication whatsoever about the folder in which the file may be stored.

One single call to our sysFileFind function would very quickly return the fully qualified filename for NWIND.MDB if the file exists, or a zero length string if it does not.

Should you have knowledge of the folder where NWIND.MDB is supposed to be located, you could use sysFileFind to scan that folder and any of its subfolders.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.