Need Faster file get name & date routine.


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Need Faster file get name & date routine.

Hybrid View

  1. #1
    Tom Sell Guest

    Need Faster file get name & date routine.


    Hello,

    I'm using the following VB6 code fragment to read, for a given folder, all
    the file names
    and their associated modified times. This works ok up to about 4000 items,
    then the time
    to read the next 1000 begins to increase dramatically. I've got between
    25K-30K items per
    folder to read. The whole reason I do this anyway is so that I can sort
    the times, and then
    process the files sequentailly based on the modified date. The array is
    dim'd at a large
    number (50K) but changing it doesn't seem to effect performance.

    This is reading from a CD, and reading from a local HD is only slightly faster.
    The performance monitory shows the time being spent in the kernal.

    Stats: 2000 items: 79 seconds, 4000 items: 300 seconds, 24000 items: 9750
    seconds

    Any suggestions?

    I've enjoyed reading the other posts. Thanks for having this forum!

    Tom.


    '
    ' Procedure to get all the file name and date/time pairs.
    ' Use i to just loop through.
    ' Set T1 to the start time.
    ' Folderspec is of the format: d:\04112000\
    '
    Set fs = CreateObject("scripting.FileSystemObject")
    Set f = fs.GetFolder(folderspec)
    Set fc = f.Files
    i = 0
    j = 1
    strT1 = CStr(Time)
    For Each fl In fc
    i = i + 1
    aryFiles(i, 1) = fl.Name
    aryFiles(i, 2) = fl.DateLastModified
    '
    ' Display a message box for every 1000.
    ' Use j to count how many times this loops trough.
    ' Use T2 for the interval end time.
    ' Reset the beginning time (T1), so the display is an interval.
    '
    If i > (1000 * j) Then
    strT2 = CStr(Time)
    strTmpB = strRoutineDisp + strT1 + "->" + strT2 + " = " + CStr(DateDiff("s",
    strT1, strT2))
    MsgBox CStr(1000 * j) + " loaded." + vbCrLf + strTmpB
    strT1 = strT2
    j = j + 1
    End If
    Next

    Share on Google+

  2. #2
    Karl E. Peterson Guest

    Re: Need Faster file get name & date routine.

    Hi Tom --

    My honest, best advice is to *throw-away* that damnedable FileSystem object! It's
    really an abomination if performance matters even a whit. See
    http://www.mvps.org/vbnet/code/filea...apicompare.htm for a comparison between
    that "thing" and native APIs. If you have trouble with the API approach, feel free
    to post in news://news.devx.com/vb.api for further assistance.

    Later... Karl


    "Tom Sell" <thomas.sell@sembach.af.mil> wrote in message
    news:38feec92$1@news.devx.com...
    >
    > Hello,
    >
    > I'm using the following VB6 code fragment to read, for a given folder, all
    > the file names
    > and their associated modified times. This works ok up to about 4000 items,
    > then the time
    > to read the next 1000 begins to increase dramatically. I've got between
    > 25K-30K items per
    > folder to read. The whole reason I do this anyway is so that I can sort
    > the times, and then
    > process the files sequentailly based on the modified date. The array is
    > dim'd at a large
    > number (50K) but changing it doesn't seem to effect performance.
    >
    > This is reading from a CD, and reading from a local HD is only slightly faster.
    > The performance monitory shows the time being spent in the kernal.
    >
    > Stats: 2000 items: 79 seconds, 4000 items: 300 seconds, 24000 items: 9750
    > seconds
    >
    > Any suggestions?
    >
    > I've enjoyed reading the other posts. Thanks for having this forum!
    >
    > Tom.
    >
    >
    > '
    > ' Procedure to get all the file name and date/time pairs.
    > ' Use i to just loop through.
    > ' Set T1 to the start time.
    > ' Folderspec is of the format: d:\04112000\
    > '
    > Set fs = CreateObject("scripting.FileSystemObject")
    > Set f = fs.GetFolder(folderspec)
    > Set fc = f.Files
    > i = 0
    > j = 1
    > strT1 = CStr(Time)
    > For Each fl In fc
    > i = i + 1
    > aryFiles(i, 1) = fl.Name
    > aryFiles(i, 2) = fl.DateLastModified
    > '
    > ' Display a message box for every 1000.
    > ' Use j to count how many times this loops trough.
    > ' Use T2 for the interval end time.
    > ' Reset the beginning time (T1), so the display is an interval.
    > '
    > If i > (1000 * j) Then
    > strT2 = CStr(Time)
    > strTmpB = strRoutineDisp + strT1 + "->" + strT2 + " = " + CStr(DateDiff("s",
    > strT1, strT2))
    > MsgBox CStr(1000 * j) + " loaded." + vbCrLf + strTmpB
    > strT1 = strT2
    > j = j + 1
    > End If
    > Next
    >



    Share on Google+

Similar Threads

  1. How long before the next version??
    By _CAG in forum .NET
    Replies: 146
    Last Post: 08-12-2002, 10:40 PM
  2. Replies: 12
    Last Post: 05-18-2001, 04:05 AM
  3. file access date ...
    By Harsha Bhogle in forum VB Classic
    Replies: 0
    Last Post: 03-16-2001, 02:50 PM
  4. file name==class name. why?
    By siva in forum Java
    Replies: 2
    Last Post: 01-03-2001, 10:40 AM
  5. File Date & Time
    By Joe P in forum authorevents.appleman
    Replies: 1
    Last Post: 04-11-2000, 04:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center