Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How dya create that little 'window' that shows files being copied??

Status
Not open for further replies.

dubble07

Programmer
May 8, 2002
12
CA

I dont want my users to think that nothings happening - when they click a 'copy file' button.

Thanks in advance!!
 
you'll need API

Code:
Option Explicit

Private Type SHFILEOPSTRUCT
  hWnd As Long
  wFunc As Long
  pFrom As String
  pTo As String
  fFlags As Integer
  fAnyOperationsAborted As Boolean
  hNameMappings As Long
  lpszProgressTitle As String
End Type

Private Declare Function SHFileOperation _
                Lib "shell32.dll" _
                Alias "SHFileOperationA" _
                (lpFileOp As SHFILEOPSTRUCT) As Long

Private Const FO_COPY = &H2
Private Const FOF_NOCONFIRMATION = &H10  '  Don't prompt the user.
Private Const FOF_NOCONFIRMMKDIR = &H200 '  don't confirm making any needed dirs

Private Function MyCopy(ByVal sSource As String, _
                        ByVal sTarget As String) As Boolean
  Dim sh_op As SHFILEOPSTRUCT
  
  With sh_op
    .hWnd = 0
    .wFunc = FO_COPY
    .pFrom = sSource & vbNullChar & vbNullChar
    .pTo = sTarget & vbNullChar & vbNullChar
    .fFlags = FOF_NOCONFIRMATION Or FOF_NOCONFIRMMKDIR
  End With

  If SHFileOperation(sh_op) = 0 Then
    MyCopy = True
  Else
    MyCopy = False
    If sh_op.fAnyOperationsAborted Then
      MsgBox "Unable to copy " & sSource & " to " & _
             sTarget & " (User aborted operation)", vbExclamation
    Else
      MsgBox "Unable to copy " & sSource & " to " & _
             sTarget & " (Unknown error)", vbExclamation
    End If
  End If
End Function

Private Sub Command1_Click()
  Dim sSource As String
  Dim sTarget As String
  
  sSource = "F:\From I\downloads\aviss\sheep-intro.avi"
  sTarget = "J:\1\2\3\4\5\6\sheep-intro.avi"
  
  If MyCopy(sSource, sTarget) Then
    MsgBox "OK", vbInformation
  End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top