呵呵,微软自己的进度都搞不定呢。
好,闲话少说,你要依据什么来确定它的进度呢?
是已经COPY的文件的SIZE相对总的来说,还是已经COPY的文件的COUNT相对总
的来说,还是已经COPY的目录的COUNT相对总的来说?
大家才能帮你。
好,闲话少说,你要依据什么来确定它的进度呢?
是已经COPY的文件的SIZE相对总的来说,还是已经COPY的文件的COUNT相对总
的来说,还是已经COPY的目录的COUNT相对总的来说?
大家才能帮你。
在执行下一语句时,进度条显示为100%
不是吧,你有两颗星哪,还是标准答案来了.竟然出这种锼主意??????
to:wangsitao(飞猪)
误差还是不要太大好.
谢谢!各位请继续.
首先要获得磁盘寻道时间,文件传输速度,所有文件的大小,数目再计算,显示,建议最好用VC写你可以参考一些安装程序的安装进度条的制作原理!!!!!!!!!!!!!!!!!!
你可以考虑以下两位的建议
songyangk(小草) ,enmity(灵感之源)
希望大家都能在CSDN上解决问题!
这才是真正的目的,也是我来CSDN的原因
Function CopyFile(Src As String, Dst As String) As Single
Static Buf As String
Dim needsize, Fizesize As Single
Dim Chunk, i2, i1 As Integer Const BUFizesize = 1024 If Len(Dir(Dst)) Then
Response = MsgBox(Dst + Chr(10) + Chr(10) + "文件已存在,覆盖吗?", vbYesNo + vbQuestion) 'prompt the user with a message box
If Response = vbNo Then
Exit Function
Else
'如果文件存在,先删除文件
Kill Dst
End If
End If
' On Error GoTo FileCopyError
i1 = FreeFile
Open Src For Binary As i1
i2 = FreeFile
Open Dst For Binary As i2
Fizesize = LOF(i1)
needsize = Fizesize - LOF(i2)
Do
If needsize < BUFizesize Then
Chunk = needsize
Else
Chunk = BUFizesize
End If
Buf = String(Chunk, " ")
Get i1, , Buf
Put i2, , Buf
needsize = Fizesize - LOF(i2)
'显示copy进程
copybar.Value = (100 - Int(100 * needsize / Fizesize)) Loop Until needsize = 0
Close i1
Close i2
CopyFile = Fizesize
copybar.Value = 0
Exit FunctionFileCopyError:
MsgBox "拷贝没有完成"
Close i1
Close i2
Exit FunctionEnd Function
Public Function getpath(inpath As String) As String
Dim I As Integer
Dim outpath As String
On Error Resume Next
For I = Len(inpath) To 1 Step -1
If Mid(inpath, I, 1) = "\" Then
outpath = Mid(inpath, I + 1)
Exit For
End If
Next I getpath = outpathEnd FunctionPrivate Sub copytopath_Click()
Dim br As BROWSEINFO
Dim hhh, ppp As Long
Dim path As String
Dim pos As Integer br.hOwner = Me.hWnd
br.lpszTitle = "目标路径"
br.ulFlags = brF_RETURNONLYFSDIRS
ppp = SHBrowseForFolder(br)
path = Space(512)
t = SHGetPathFromIDList(ByVal ppp, ByVal path) pos = InStr(path, Chr$(0))
inpath = Left(path, pos - 1) If Right$(inpath, 1) = "\" Then
outpath = inpath
Else
outpath = inpath + "\"
End If
Destinationpath.Text = outpath + getpath(Filepath.Text)
End SubPrivate Sub Browsefile_Click()
Dialog.DialogTitle = "源文件路径"
Dialog.ShowOpen
Filepath.Text = Dialog.FileName
End SubPrivate Sub Command1_Click()
Unload Me
End SubPrivate Sub Copy_Click()
On Error Resume Next If Filepath.Text = "" Then
MsgBox "你没有选择拷贝文件", vbCritical
Exit Sub
End If
If Destinationpath.Text = "" Then
MsgBox "你没有选择目标路径", vbCritical
Exit Sub
End If copybar.Value = CopyFile(Filepath.Text, Destinationpath.Text)
End SubPrivate Sub filepath_Change()
Destinationpath.Enabled = True
copytopath.Enabled = True
' Destinationpath.SetFocus
End Sub
Private Sub form_load()
Filepath.Text = "c:\ndr20001229\sftcc.mdb"
Destinationpath.Text = "c:\ndr20001229\backup\sftcc.mdb"
End Sub
Dialog 打开文件对话框
Copy 一个Command 用于拷贝
你是否以前就把这段代码公开过?我见到过,用拷贝一幅.bmp图片测了一下.拷贝后的图片不能显示. 可能有些不同,我想试试吧.谢谢 !
to: enmity(灵感之源)
[email protected] 谢谢!
enmity(灵感之源)
谢谢!你给我发的东西我已经收到了.可是好像没什么用.我自己写了一点,帮我看看好吗?
Option Explicit
Private intProgressBarMax As Integer
Dim fso As New FileSystemObject
Dim fld As Folder
Dim fld1 As Folder Private counter As Long '记录f 文件夹的大小
Private counter1 As Long '记录f2文件夹的大小
Private counter2 As Long '记录进度条的当前值
'***************************************************************
e:\f 源路径
e:\f2 目标路径(输出路径)
'*************************************************************** Private Sub Command1_Click()
ProgressBar1.Value = 0
ProgressBar1.Visible = True
fso.CopyFolder "e:\f\*", "e:\f2\"
fso.CopyFile "e:\f\*", "e:\f2\"
Timer1.Enabled = True
End SubPrivate Sub Form_Load()
Set fld = fso.GetFolder("e:\f")
Set fld1 = fso.GetFolder("e:\f2")
counter = fld.Size
intProgressBarMax = 100
With Timer1
.Enabled = False
.Interval = 100
End With
End SubPrivate Sub Timer1_Timer()
counter1 = fld1.Size
If counter1 = counter Then
Timer1.Enabled = False
counter2 = 0
ProgressBar1.Visible = False
MsgBox "完毕!"
Exit Sub
Else
counter2 = counter Mod counter1
ProgressBar1.Value = (counter2 * 100)
End If
End Sub
进度条没反应
在适当的地方加个doevents试试。
Private m_intItems As Integer
Private Sub cmdSetup_Click()
ReDim m_strFiles(0 To 2) As String '这里自己定义
m_strFiles(0) = "program.exe"
m_strFiles(1) = "data.dat"
m_strFiles(2) = "readme.chm"
For m_intItems = LBound(m_strFiles) To UBound(m_strFiles)
FileCopy App.Path & "\" & m_strFiles(m_intItems), "c:\program files\My Program\" & m_strFiles(m_intItems)
pbSetup.Value = ((m_intItems + 1) / (UBound(m_strFiles) + 1)) * 100
DoEvents
Next
End Sub
其实直接用IO文件读写可以做到精确进度,只不过会牺牲很大的速度。
你用的什么办法?如果是 ReadFile/WriteFile 等API,那么你一个字节一个字节的读写,比1MB 1MB的读写慢很多。(我写过文件切割软件,多种办法都试过)如果用更底层的IO……我估计难度可想而知。
而且,帖子我都看过了,我想好象没理解错 ^_^以上均为个人观点,欢迎指点。
代码就不写啦,就这个意思,你应该可以自己搞定的。