Home > Microsoft .Net Development Tips > ARCHIVE: Tips & Tricks > Waiting for Godot..er..copy
Win Development Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ARCHIVE: TIPS & TRICKS

Waiting for Godot..er..copy


Richard Deeming
11.14.2000
Rating: -4.25- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


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.

 
Type SHFILEOPSTRUCTStr
    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
 
Dim SHFOS As SHFILEOPSTRUCTStr
    With SHFOS
        .hWnd = hWnd
        .pFrom = From
        .pTo = To
        .wFunc = Operation
        .fFlags = Flags
        .lpszProgressTitle = SimpleProgressTitle
    End With
    SHFileOperationStr SHFOS

    If SHFOS.fAnyOperationsAborted Then
        DoFileOp = False
    Else
        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
Kill(txtFle)
Exit Sub
 
impErr:
Msgbox "Error importing data: " & Err.Number & " - " & 
Err.Description
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.


Rate this Tip
To rate tips, you must be a member of SearchWinDevelopment.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
ARCHIVE: Tips & Tricks
SearchVB wants your tips
Find out what VS.NET modules are installed
Retrieving icons from an EXE-file
Toggling Boolean values
VS.NET multiple tabbed windows
Set the value of a DataField in code behind
Easy grid design
Open using last Visual Studio.NET layout
Save development time by using inherited forms
Reusing code in VS.NET

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

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.



Database Programming Solutions - .NET XML, Visual Studio LINQ, ORM .NET
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts