Top Ten Files

Lance_Corporal

New member
Joined
Aug 31, 2015
Messages
1
Programming Experience
10+
I wonder if someone has a suggestion. I've written a service in VB.Net 2008 that monitors local folders. The service reads the files from the folders and if the workstation is connected to the
network the service will copy files to a remote folder based on entries in the config file.

There are times when the workstations will be disconnected from the network for months and so when they are reconnected there can be hundreds of thousands of files which the service will
happily began copying to remote folders which will flood some ques.

The filenames are retrieved using GETFILES

My question is this: Is there a way to grab just the first 10 file names in a folder? Currently I have a counter but the problem is there are some systems where the file count can exceed
one million so instead of even entering a loop that large I would like to just grab the top 10 file names based on the oldest file in the folder.

Please don't give posts on best practices or just insure the machine is on the network, there are business practices in place that cause these problems to occur. I just need to figure out a way
to have the system grab a few files at a time.
 
If you can upgrade to .Net 4 or higher you can use EnumerateFiles instead of GetFiles, that will return the names as you enumerate them rather than wait for all names to be collected. If not you have to use the Windows API directly, see for example io - EnumerateFiles() equivalent in .NET 3.5 - Stack Overflow
 

Latest posts

Back
Top