[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:
Option Explicit
Private Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS
End Type
Private Const FOF_MULTIDESTFILES = &H1
Private Const FOF_CONFIRMMOUSE = &H2
Private Const FOF_SILENT = &H4
Private Const FOF_RENAMEONCOLLISION = &H8
Private Const FOF_NOCONFIRMATION = &H10
Private Const FOF_WANTMAPPINGHANDLE = &H20
Private Const FOF_CREATEPROGRESSDLG = &H0
Private Const FOF_ALLOWUNDO = &H40
Private Const FOF_FILESONLY = &H80
Private Const FOF_SIMPLEPROGRESS = &H100
Private Const FOF_NOCONFIRMMKDIR = &H200
Private Const FO_MOVE = 1
Private Const FO_COPY = 2
Private Const FO_DELETE = 3
Private Const FO_RENAME = 4
Private Declare Function SHFileOperation Lib "shell32.dll" (lpFileOp As SHFILEOPSTRUCT) As Long
Public Function CopyFolder(ByVal strSource As String, ByVal strDest As String) As Boolean
'=========================================================================================
Dim varFOS As SHFILEOPSTRUCT
With varFOS
.fFlags = FOF_NOCONFIRMATION Or FOF_SILENT Or FOF_NOCONFIRMMKDIR
.wFunc = FO_COPY
.pFrom = strSource
.pTo = strDest
End With
Call SHFileOperation(varFOS)
CopyFolder = (varFOS.fAnyOperationsAborted = 0)
End Function
Private Sub Command1_Click()
CopyFolder "c:\temp\test", "c:\temp\test2"
End Sub
Re: Progress bar when copying folders/files ?
you need to change the flags,
VB Code:
Public Function CopyFolder(ByVal strSource As String, ByVal strDest As String) As Boolean
'=========================================================================================
Dim varFOS As SHFILEOPSTRUCT
With varFOS
[COLOR=DarkRed] [B] .fFlags =FOF_CREATEPROGRESSDLG[/B][/COLOR]
.wFunc = FO_COPY
.pFrom = strSource
.pTo = strDest
End With
Call SHFileOperation(varFOS)
CopyFolder = (varFOS.fAnyOperationsAborted = 0)
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:
.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:
Private Declare Function SHFileOperation Lib "shell32.dll" (lpFileOp As SHFILEOPSTRUCT) As Long
Public Function CopyFolder(ByVal strSource As String, ByVal strDest As String) As Boolean
'=========================================================================================
Dim varFOS As SHFILEOPSTRUCT
With varFOS
.wFunc = FO_COPY
.pFrom = strSource
.pTo = strDest
End With
Call SHFileOperation(varFOS)
CopyFolder = (varFOS.fAnyOperationsAborted = 0)
End Function
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!
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?