Two Different Ways of Listing All Files in a Directory

Files and Directories

Author: Intelligent Solutions Inc.

Version Compatibility: Visual Basic 6

More information:
These two functions, AllFiles and APIAllFiles, return a string array containing all the file names within a given drive or subdirectory. The first, AllFiles, uses the Dir function, wherease the second, APIAllFiles, uses the FindFirstFile and FindNextFile API functions. They return the names of all files (including hidden, system, and read only files), but not subdirectory names. And they do not peform recursive searches.

Though the API method is supposedly faster, the Dir function was faster in this case, in my tests at least. However, this probably has a lot to do with all the attribute checking done in the second function, which is required to make it generic and to ensure that subdirectory names are not included. You may get different results if you change the code for your own purposes.

Refer to the comments for more information about what these functions do and how to call them.

Instructions: Copy the declarations and code below and paste directly into your VB project.