Results 1 to 2 of 2

Thread: Copy File in Backround

  1. #1

    Thread Starter
    Addicted Member DanCool999's Avatar
    Join Date
    Jul 2006
    Posts
    141

    Copy File in Backround

    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
    Dan " "

    Visual Basic Professional 6.0

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Copy File in Backround

    I believe you can do that SHFileOperation API

    edit:

    here is an example for you...

    vb Code:
    1. Option Explicit
    2.  
    3. Private Declare Function SHFileOperation Lib "shell32.dll" _
    4. Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
    5.  
    6. Const FO_COPY = &H2 '~~> Copy File/Folder
    7. Const FOF_SILENT = &H4 '~~> Silent Copy
    8.  
    9. Private Type SHFILEOPSTRUCT
    10.     hwnd      As Long
    11.     wFunc     As Long
    12.     pFrom     As String
    13.     pTo       As String
    14.     fFlags    As Integer
    15.     fAborted  As Boolean
    16.     hNameMaps As Long
    17.     sProgress As String
    18. End Type
    19.  
    20. Private Sub Command1_Click()
    21.     Dim lresult  As Long, lFlags   As Long
    22.     Dim SHFileOp As SHFILEOPSTRUCT
    23.  
    24.     Screen.MousePointer = vbHourglass
    25.  
    26.     With SHFileOp
    27.         '~~> For Copy
    28.         .wFunc = FO_COPY
    29.         '~~> txtSource.Text will hold the source folder/File
    30.         .pFrom = txtSource.Text & vbNullChar & vbNullChar
    31.         '~~> txtDestination.Text will hold the destination folder/File
    32.         .pTo = txtDestination.Text & vbNullChar & vbNullChar
    33.         '~~> For Silent Copy
    34.         .fFlags = FOF_SILENT
    35.     End With
    36.     lresult = SHFileOperation(SHFileOp)
    37.  
    38.     Screen.MousePointer = vbDefault
    39.    
    40.     '~~> SHFileOp.fAborted will be true if user presses cancel during operation
    41.     If lresult <> 0 Or SHFileOp.fAborted Then Exit Sub
    42.    
    43.     MsgBox "Operation Complete", vbInformation, "File Operations"
    44. End Sub
    Last edited by Siddharth Rout; Mar 29th, 2009 at 06:02 PM.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width