• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 487
  • Last Modified:

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.  
0
bradfordcogswell
Asked:
bradfordcogswell
  • 2
1 Solution
 
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
 
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

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now