I need to get a list of file names (that I'll probably store in an array) from a determined directory sorted by file name, so I can process them correctly. I could have up to 10,000 files in this directory, so loading the names in an array and sorting them is not the best solution.

Does anybody know a registry setting (files getting sorted as they get dropped inside the directory), an API call or a piece of code that could solve my problem?

I have a couple of proposed solutions but none of them are bullet proof!

1 - Load all the files into an array. Read file by file (go one at a time in the array), until end of array. Load array again with new file names that have been dropped in the folder. Sort array when loaded(once)

2 - Use a file control. Load Filelist, process file, refresh file list.
(kind of slow if more then 5000 files). The refreshing is very slow (0.5
seconds per batch. So I after processing each file, If I want to get a
snapshot of the latest in the folder, I will be wasting too much time!)

Both solutions won't let me "watch" the directory at all times and let me get a snapshot of the latest file list I have. This app is supposed to be a "listener". I will be grabbing the files and process them accordingly. They need to be processed in a certain order (by file name!). After they are processed, they are moved somewhere else!

In the ideal world I would be loading the filelist control or the array at all times(every second, or after each process)... But the sorting will take too long if I do that... I got to process those files faster......

I've tried with arrays... It seems to be slower than using the following example where I used a FileList(for some reason, it's sorting by name by default) control. For a load of 3000 files, it only took 70 milliseconds to
refresh. The reason why I wanted to sort the files before getting a list is because I could use a fast API call (GetFirst()) instead of even getting a list and loading this list somewhere (control or array).

FileList.Path = "c:\new" 'I created 3000 files within this directory
Label1.Caption = GetTickCount 'API call to determine the number of
milliseconds that has elapsed since windows was started
FileList.Refresh
Label2.Caption = GetTickCount 'API call to determine the number of
milliseconds that has elapsed since windows was started
Label3.Caption = Str(Int(Label2.Caption) - Int(Label1.Caption)) 'to see
how many milliseconds it actually too to refresh the control.
Form1.Caption = FileList.ListCount & " files in the directory"

You may be asking yourself!!!! Only 70 milliseconds???? Yeah, but if I have 3000 files (70 milliseconds x 3000 refreshes = 210 seconds or about 3.5 minutes), this 70 milliseconds can make a difference. I still need to add
the overhead of opening and closing the file, passing the file's contents (XML) to a COM+ object, waiting to parse the XML and finally inserting into a database. And if I need to refresh the control 3000 times, my app will
hog!!!

The reason behind my posting is because I will be receiving files (at random times) from 3 different systems. The files being dumped are dependents of
each other, and that's why I need to process them in a certain order. And the file naming convention will determine this dependency. That's the reason
why I need to sort the files by name!!!!