What is the simplest way to copy a file in the background while the form still has full functionality and then display a messagebox when it has finished copying. The file is a bit large (277 mb).
Thanks :)
Printable View
What is the simplest way to copy a file in the background while the form still has full functionality and then display a messagebox when it has finished copying. The file is a bit large (277 mb).
Thanks :)
I believe you can do that SHFileOperation API :)
edit:
here is an example for you...
vb Code:
Option Explicit Private Declare Function SHFileOperation Lib "shell32.dll" _ Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long Const FO_COPY = &H2 '~~> Copy File/Folder Const FOF_SILENT = &H4 '~~> Silent Copy Private Type SHFILEOPSTRUCT hwnd As Long wFunc As Long pFrom As String pTo As String fFlags As Integer fAborted As Boolean hNameMaps As Long sProgress As String End Type Private Sub Command1_Click() Dim lresult As Long, lFlags As Long Dim SHFileOp As SHFILEOPSTRUCT Screen.MousePointer = vbHourglass With SHFileOp '~~> For Copy .wFunc = FO_COPY '~~> txtSource.Text will hold the source folder/File .pFrom = txtSource.Text & vbNullChar & vbNullChar '~~> txtDestination.Text will hold the destination folder/File .pTo = txtDestination.Text & vbNullChar & vbNullChar '~~> For Silent Copy .fFlags = FOF_SILENT End With lresult = SHFileOperation(SHFileOp) Screen.MousePointer = vbDefault '~~> SHFileOp.fAborted will be true if user presses cancel during operation If lresult <> 0 Or SHFileOp.fAborted Then Exit Sub MsgBox "Operation Complete", vbInformation, "File Operations" End Sub