Results 1 to 4 of 4

Thread: [RESOLVED] Progress bar when copying folders/files ?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830

    Resolved [RESOLVED] Progress bar when copying folders/files ?

    Hello,

    I found the code below on this forum and it appears to work great. When copying folders/files it does not show the typical window that shows pages flying through the air. All it shows is an hour glass. I would like SOMETHING that indicates the folders/files are being copied and SOMETHING that shows when it is done. Am I on the right track with the code below and can I add a progress bar for the code below?

    Thanks!

    http://vbforums.com/showthread.php?t...y+files+folder

    VB Code:
    1. Option Explicit
    2.  
    3. Private Type SHFILEOPSTRUCT
    4.         hwnd As Long
    5.         wFunc As Long
    6.         pFrom As String
    7.         pTo As String
    8.         fFlags As Integer
    9.         fAnyOperationsAborted As Long
    10.         hNameMappings As Long
    11.         lpszProgressTitle As String '  only used if FOF_SIMPLEPROGRESS
    12. End Type
    13.  
    14. Private Const FOF_MULTIDESTFILES = &H1
    15. Private Const FOF_CONFIRMMOUSE = &H2
    16. Private Const FOF_SILENT = &H4
    17. Private Const FOF_RENAMEONCOLLISION = &H8
    18. Private Const FOF_NOCONFIRMATION = &H10
    19. Private Const FOF_WANTMAPPINGHANDLE = &H20
    20. Private Const FOF_CREATEPROGRESSDLG = &H0
    21. Private Const FOF_ALLOWUNDO = &H40
    22. Private Const FOF_FILESONLY = &H80
    23. Private Const FOF_SIMPLEPROGRESS = &H100
    24. Private Const FOF_NOCONFIRMMKDIR = &H200
    25.  
    26. Private Const FO_MOVE = 1
    27. Private Const FO_COPY = 2
    28. Private Const FO_DELETE = 3
    29. Private Const FO_RENAME = 4
    30.  
    31. Private Declare Function SHFileOperation Lib "shell32.dll" (lpFileOp As SHFILEOPSTRUCT) As Long
    32.    
    33. Public Function CopyFolder(ByVal strSource As String, ByVal strDest As String) As Boolean
    34. '=========================================================================================
    35. Dim varFOS As SHFILEOPSTRUCT
    36.     With varFOS
    37.         .fFlags = FOF_NOCONFIRMATION Or FOF_SILENT Or FOF_NOCONFIRMMKDIR
    38.         .wFunc = FO_COPY
    39.         .pFrom = strSource
    40.         .pTo = strDest
    41.     End With
    42.     Call SHFileOperation(varFOS)
    43.     CopyFolder = (varFOS.fAnyOperationsAborted = 0)
    44. End Function
    45.  
    46. Private Sub Command1_Click()
    47.     CopyFolder "c:\temp\test", "c:\temp\test2"
    48. End Sub

  2. #2
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Re: Progress bar when copying folders/files ?

    you need to change the flags,

    VB Code:
    1. Public Function CopyFolder(ByVal strSource As String, ByVal strDest As String) As Boolean
    2. '=========================================================================================
    3. Dim varFOS As SHFILEOPSTRUCT
    4.     With varFOS
    5.  
    6.      [COLOR=DarkRed] [B]  .fFlags =FOF_CREATEPROGRESSDLG[/B][/COLOR]
    7.  
    8.         .wFunc = FO_COPY
    9.         .pFrom = strSource
    10.         .pTo = strDest
    11.     End With
    12.     Call SHFileOperation(varFOS)
    13.     CopyFolder = (varFOS.fAnyOperationsAborted = 0)
    14. End Function

    or you can have Various other choices if the dir already exists and you dont want confirmation to replace it then

    VB Code:
    1. .fFlags = FOF_NOCONFIRMATION

    just use no flags and it give you a progress dialog and ask for confirmation etc.. all defaults.. like this,

    VB Code:
    1. Private Declare Function SHFileOperation Lib "shell32.dll" (lpFileOp As SHFILEOPSTRUCT) As Long
    2.    
    3. Public Function CopyFolder(ByVal strSource As String, ByVal strDest As String) As Boolean
    4. '=========================================================================================
    5. Dim varFOS As SHFILEOPSTRUCT
    6.     With varFOS
    7.          .wFunc = FO_COPY
    8.         .pFrom = strSource
    9.         .pTo = strDest
    10.     End With
    11.     Call SHFileOperation(varFOS)
    12.     CopyFolder = (varFOS.fAnyOperationsAborted = 0)
    13. End Function

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830

    Re: Progress bar when copying folders/files ?

    Excellent! I was talking about a VB Progress bar...but this is all I really need and probably exceeds what I need. Great stuff! Thanks!

  4. #4
    Junior Member
    Join Date
    May 2006
    Posts
    26

    Re: [RESOLVED] Progress bar when copying folders/files ?

    Guys .. pls help.

    If I want "CopyFolder" to start from the current folder the program is in, how do I do it?

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