[英]Copy files with progress bar
So I am trying to do something in visual basic I start learning but still that is not enough. 因此,我试图在视觉基础上做一些我开始学习的事情,但那还不够。 Mostly I am using codes from internet. 通常,我使用的是来自互联网的代码。 Now I want to copy few files from first folder to second folder and overwrite existing files and I want to see progress on progress bar (all files together are about 2GB) 现在,我想将几个文件从第一个文件夹复制到第二个文件夹并覆盖现有文件,我想在进度条上看到进度(所有文件合在一起约为2GB)
SOLVED: I found source code for some program and used some parts to make this work 求助:我找到了一些程序的源代码,并使用了一些部分来完成这项工作
Here is my favorite way of doing it... Using the SHFileOperation
API 这是我最喜欢的方法...使用SHFileOperation
API
This API will automatically show the progress as shown in the screenshot below. 该API将自动显示进度,如下面的屏幕快照所示。
Here is an example. 这是一个例子。 Paste this code in a module 将此代码粘贴到模块中
Public Declare Function SHFileOperation Lib "shell32.dll" _
Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Public Const FO_COPY = &H2
Public Const FOF_SIMPLEPROGRESS = &H100
Public 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 Long
End Type
Public Sub VBCopyFolder(ByRef strSource As String, ByRef strTarget As String)
Dim op As SHFILEOPSTRUCT
With op
.wFunc = FO_COPY
.pTo = strTarget
.pFrom = strSource
.fFlags = FOF_SIMPLEPROGRESS
End With
'~~> Perform operation
SHFileOperation op
End Sub
and then copy files or folders like this 然后像这样复制文件或文件夹
Private Sub Sample()
'~~> Copy Files
Call VBCopyFolder("C:\Sample.Avi", "C:\NewSample.Avi")
'~~> Copy Folders
Call VBCopyFolder("C:\Temp1", "C:\Temp2")
End Sub
Screenshot 屏幕截图
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.