Waiting for Godot..er..copy

Waiting for Godot..er..copy
Richard Deeming

They also serve who only stand wait. This tip, from reader Richard Deeming, shows another method for allowing a program to stand and wait for a copy operation to complete, and adds some enhancements to the basic idea, which we have discussed in the past, as well.

There is a simple way to copy files and wait for the copy to complete. This method will also (optionally) show the standard Windows file-copy progress dialog box.

    hWnd As Long
    wFunc As Long
    pFrom As String
    pTo As String
    fFlags As Integer
    fAnyOperationsAborted As Long
    hNameMappings As Long
    lpszProgressTitle As String
End Type
Enum FO_Func
    FO_Move = 1
    FO_Copy = 2
    FO_Delete = 3
    FO_Rename = 4
End Enum
Enum FO_Flags
    FOF_MultiDestFiles = &H1
    FOF_ConfirmMouse = &H2
    FOF_Silent = &H4
    FOF_RenameOnCollision = &H8
    FOF_NoConfirmation = &H10
    FOF_WantMappingHandle = &H20
    FOF_AllowUndo = &H40
    FOF_FilesOnly = &H80
    FOF_SimpleProgress = &H100
    FOF_NoConfirmMkDir = &H200
    FOF_DeleteFlags = &H154
    FOF_CopyFlags = &H3DD
End Enum
Private Declare Function SHFileOperationStr Lib "shell32.dll" "
"Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCTStr) As Long
Function DoFileOp(Operation As FO_Func, sFrom As String, _
       Optional sTo As String = vbNullString, _
       Optional Flags As FO_Flags, _
       Optional SimpleProgressTitle As String = vbNullString, _
       Optional hWnd As Long) As Boolean
    With SHFOS
        .hWnd = hWnd
        .pFrom = From
        .pTo = To
        .wFunc = Operation
        .fFlags = Flags
        .lpszProgressTitle = SimpleProgressTitle
    End With
    SHFileOperationStr SHFOS

    If SHFOS.fAnyOperationsAborted Then
        DoFileOp = False
        DoFileOp = True
    End If
End Function

Thus, the function in the tip ("Transfer Downloads Automatically," mailed Nov. 7, 2000) would become:

Public Function importData()
Dim srcFle As String, txtFle As String
Dim tmpFle As String, Rslt As Boolean
Const dwnPth="bdc_serverDL"
On Error Goto impErr
' Set up file path/name variables
tmpFle = Environ("temp")
srcFle = dwnPth & "import.txt"
txtFle = tmpFle & "newdata.txt"
' Copy the file
Rslt = DoFileOp(Operation := FO_Copy, From:= srcFle, _
                To := txtFle, Flags := FOF_Silent)
' Import the text file to a database table
DoCmd.TransferText acImportDelim, "NewData import specification", _
"tblImport", txtFle, False
' Delete the text data file
Exit Sub
Msgbox "Error importing data: " & Err.Number & " - " & 
End Sub

Thanks, Richard, and for your interest in SearchVB we will be forwarding you a SearchVB denim shirt.

Richard Deeming is a Software development manager for Trinet Ltd. He is from Shoreham-by-Sea, West Sussex, UK.

This was first published in November 2000

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.