Results 1 to 4 of 4

Thread: Problems with FileSystemObject

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    2

    Problems with FileSystemObject

    I have built a VB app to take in a query of product #s, then search for all pictures associated with that product on a local machine, then those that are found are copied into a seperate file to be distributed out. The probloem I am having is that it is very slow, and yet it only uses 10% CPU Max and 17,000 k memory max. I need to find a way to speed it up, if anyone has any suggestions.

    Thanks,
    Dan

    Code snippet here (which is called passing in the ProdNums in a loop over the recordset):
    VB Code:
    1. Private Sub CopyPhotos(ProdNum)
    2.     Dim intCntr, LastTwo As Integer
    3.     Dim ThisPhoto, ThisPhotoPath As String
    4.     LastTwo = Right(ProdNum, 2)
    5.     ThisPhotoPath = RootPath & "\" & LastTwo
    6.     intCntr = 0
    7.     'On Error GoTo errHandler
    8.     'Check that the photo folder exists
    9.     If Not myFSO.FolderExists(ThisPhotoPath) Then
    10.         GoTo NoFolder
    11.     End If
    12.     'Check Desitnation Folder
    13.     If Not myFSO.FolderExists(CopyPath & "\" & LastTwo) Then
    14.         myFSO.CreateFolder CopyPath & "\" & LastTwo
    15.     End If
    16.     'Loop over all possible photo combos
    17.     Do While intCntr <= MaxPhotos
    18.         'Check for this photo
    19.         ThisPhoto = ThisPhotoPath & "\" & ProdNum& "_" & intCntr & ".jpg"
    20.         If Not myFSO.FileExists(ThisPhoto) Then
    21.             GoTo NoPhoto
    22.         End If
    23.         myFSO.CopyFile ThisPhoto, CopyPath & "\" & LastTwo & "\"
    24. NextPhoto:
    25.         intCntr = intCntr + 1
    26.     Loop
    27.     GoTo UnloadSub
    28. NoFolder:
    29.     WriteUserError ("Folder for " & ProdNum& " Photo does not exist ( " & ThisPhotoPath & " )")
    30.     GoTo UnloadSub
    31. NoPhoto:
    32.     WriteUserError ("Photo for " & ProdNum& " Photo does not exist ( " & ThisPhoto & " )")
    33.     GoTo NextPhoto
    34. UnloadSub:
    35.     Exit Sub
    36. errHandler:
    37.     If ErrMustStop Then Debug.Assert False: Resume
    38.     ErrorIn "Form1.MoveFiles(RootPath)", RootPath
    39. End Sub



    Edit: Added [vbcode][/vbcode] tags for clairty. - Hack
    Last edited by Hack; Jun 23rd, 2005 at 08:41 AM.

  2. #2
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: Problems with FileSystemObject

    The bottleneck here is your disk access. Get a faster disk. That's all you can do. Need recommendations on how to get a faster disk?
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  3. #3
    Fanatic Member ZeBula8's Avatar
    Join Date
    Oct 2002
    Posts
    548

    Re: Problems with FileSystemObject

    try this:

    just tightened it very small bit

    VB Code:
    1. Private Sub CopyPhotos(ProdNum)
    2. 'Dim intCntr, LastTwo As Integer
    3. 'Dim ThisPhoto, ThisPhotoPath As String
    4.  
    5. Dim intCntr As Long
    6. Dim LastTwo As Long
    7. Dim ThisPhoto As String
    8. Dim ThisPhotoPath As String
    9. Dim sFolder As String
    10.  
    11.  
    12.  
    13. LastTwo = Right(ProdNum, 2)
    14. sFolder = CopyPath & "\" & LastTwo
    15. ThisPhotoPath = RootPath & "\" & LastTwo
    16.  
    17. intCntr = 0
    18.  
    19. 'On Error GoTo errHandler
    20. 'Check that the photo folder exists
    21. If Not myFSO.FolderExists(ThisPhotoPath) Then
    22.     GoTo NoFolder
    23. End If
    24.  
    25. 'Check Desitnation Folder
    26. If Not myFSO.FolderExists(sFolder) Then
    27.     myFSO.CreateFolder sFolder
    28. End If
    29.  
    30. 'Loop over all possible photo combos
    31. Do While intCntr <= MaxPhotos
    32.     'Check for this photo
    33.     ThisPhoto = ThisPhotoPath & "\" & ProdNum & "_" & intCntr & ".jpg"
    34.    
    35.     If myFSO.FileExists(ThisPhoto) Then
    36.         myFSO.CopyFile ThisPhoto, sFolder & "\"
    37.     End If
    38.     intCntr = intCntr + 1
    39. Loop
    40.  
    41. GoTo UnloadSub
    42.  
    43.  
    44. NoFolder:
    45. WriteUserError ("Folder for " & ProdNum & " Photo does not exist ( " & ThisPhotoPath & " )")
    46. GoTo UnloadSub
    47.  
    48. NoPhoto:
    49. WriteUserError ("Photo for " & ProdNum & " Photo does not exist ( " & ThisPhoto & " )")
    50. GoTo NextPhoto
    51.  
    52. UnloadSub:
    53. Exit Sub
    54.  
    55. errHandler:
    56. If ErrMustStop Then Debug.Assert False: Resume
    57. ErrorIn "Form1.MoveFiles(RootPath)", RootPath
    58. End Sub

  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    2

    Re: Problems with FileSystemObject

    I appreciate the replies, I have changed my approach to now building a .bat that has all the copy commands in it, then calling that .bat. It's definately slow on the actual copy process, it builds the .bat files pretty fast. I think one of the main issues is we are talking about 15+ gigs of files and about 333,000 products with a possible 10 photos per product. I have split the bat files up into 1-9 based on the last 2 digits of the product code, and am running 2 bats at a time, trying to see if that speeds it up at all.

    If anyone has any better ideas, I would love to hear it.

    Thanks,
    Dan

Posting Permissions

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



Click Here to Expand Forum to Full Width