Results 1 to 2 of 2

Thread: Top Ten Files

  1. #1
    Lance_Corporal is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    Aug 2015

    Top Ten Files

    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.

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    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
    How to format posts with code blocks etc - present the problem/post properly

    Visual Studio Community 2017


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts