Asynchronous File Copy in VB 6.0

I am writing a utility that copies files from one location to another.  I would like to update a progress bar during the copy of large files in much the same way as Windows Explorer.  I also need to know when the copy has completed so I can continue with the next file.  
bradfordcogswellAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gambisticsCommented:
It would be worth more points, I think.
0
VbmasterCommented:
Here's a function to access the same API Explorer uses...

Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long

Public Enum FO_ACTIONS
  FO_COPY = &H2
  FO_MOVE = &H1
  FO_DELETE = &H3
End Enum

Public Enum FO_FLAGS
  FOF_SILENT = &H4
  FOF_RENAMEONCOLLISION = &H8
  FOF_NOCONFIRMATION = &H10
  FOF_SIMPLEPROGRESS = &H100
  FOF_ALLOWUNDO = &H40
End Enum

Public Function FileAPI(sSource As String, sDestination As String, Optional Action As FO_ACTIONS = FO_COPY, Optional Flags As FO_FLAGS) As Long
 
  Dim SHFileOp As SHFILEOPSTRUCT
 
  'Terminate the folder string with a pair of nulls
  sSource = sSource & Chr$(0) & Chr$(0)
 
  'Set up the options
  With SHFileOp
    .wFunc = Action
    .pFrom = sSource
    .pTo = sDestination
    .fFlags = Flags
  End With
 
  'Perform the chosen copy or move operation
  FileAPI = (SHFileOperation(SHFileOp) = 0)

End Function

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bradfordcogswellAuthor Commented:
This works like a charm.  I was curious if you had any information on the different settings for the flags:

Public Enum FO_FLAGS
  FOF_SILENT = &H4
  FOF_RENAMEONCOLLISION = &H8
  FOF_NOCONFIRMATION = &H10
  FOF_SIMPLEPROGRESS = &H100
  FOF_ALLOWUNDO = &H40
End Enum

In particular I would like to turn off the messages to confirm overwrite and to confirm directory creation.

(Hate to put you to all this trouble for 10 points.  I am new to the exchange and a little short on points.  Thanks much.  BWC)
0
bradfordcogswellAuthor Commented:
Thanks for the answer.  It worked perfectly.  BWC
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.