呵呵,微软自己的进度都搞不定呢。
好,闲话少说,你要依据什么来确定它的进度呢?
是已经COPY的文件的SIZE相对总的来说,还是已经COPY的文件的COUNT相对总
的来说,还是已经COPY的目录的COUNT相对总的来说?
大家才能帮你。

解决方案 »

  1.   

    作个假的当执行完FileCopy后才执行下一语句
    在执行下一语句时,进度条显示为100%
      

  2.   

    已经COPY的文件的COUNT相对总的来说
      

  3.   

    to :lihonggen0(李洪根,用VB,标准答案来了)
    不是吧,你有两颗星哪,还是标准答案来了.竟然出这种锼主意??????
    to:wangsitao(飞猪)
    误差还是不要太大好.
    谢谢!各位请继续.
      

  4.   

    为什么不调用SHFileOperation,给个理由先
      

  5.   

    to : enmity(灵感之源) ,一个大文件,怎么处理?我认为:
    首先要获得磁盘寻道时间,文件传输速度,所有文件的大小,数目再计算,显示,建议最好用VC写你可以参考一些安装程序的安装进度条的制作原理!!!!!!!!!!!!!!!!!!
      

  6.   

    to : enmity(灵感之源) ,只有一个大文件,怎么处理?
      

  7.   

    to:lihonggen0(李洪根,用VB,标准答案来了) 文件大小与根据文件数目来计算进度有关系么?如果像你精确得要计算寻道、传输等速度,我看,10000个软件,没有几个软件会这样干当前,大部分的做法:计算文件大小,按照复制字节数计算我认为,简单点,可以采用文件数量来计算
      

  8.   

    to:lihonggen0(李洪根,用VB,标准答案来了) 你自己也说了:微软自己的进度都搞不定连软件巨人也这样,是它没有技术?是因为如果真的按照你的说法去做,实在是有舍本逐末的意味,不做也罢。
      

  9.   

    to:lihonggen0(李洪根,用VB,标准答案来了) “一般用户也应该能接受!”,你这么说来,是不赞同了。不要紧,如果你找到满意的方法,可以考虑拿出来,跟大家分享。
      

  10.   

    to:lihonggen0(李洪根,用VB,标准答案来了) “一般用户也应该能接受!”,你这么说来,是不赞同了。不要紧,如果你找到满意的方法,可以考虑拿出来,跟大家分享。
      

  11.   

    大家还有好的建议吗?to :  tony_jian (神经质男主角)  
    你可以考虑以下两位的建议
     songyangk(小草) ,enmity(灵感之源)
      

  12.   

    to : enmity(灵感之源) 我赞同你的观点
    希望大家都能在CSDN上解决问题!
    这才是真正的目的,也是我来CSDN的原因
      

  13.   

    to:tony_jian(神经质男主角) 其实并不烦琐,我想,你之所以觉得烦琐,该不会是具体到每个文件这样写吧?你可以做一个函数,返回总文件数和文件总自己量。代码不会超过30行。
      

  14.   


    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
      

  15.   

    to:tony_jian(神经质男主角) 其实并不烦琐,我想,你之所以觉得烦琐,该不会是具体到每个文件这样写吧?你可以做一个函数,返回总文件数和文件总自己量。代码不会超过30行。
      

  16.   

    to:tony_jian(神经质男主角) 留下email,给你一个相关例子。
      

  17.   

    '以上代码是我为天津外经贸委写的一段程序copybar  进度条
    Dialog  打开文件对话框
    Copy    一个Command 用于拷贝
      

  18.   

    to : lihonggen0(李洪根,用VB,标准答案来了) 
    你是否以前就把这段代码公开过?我见到过,用拷贝一幅.bmp图片测了一下.拷贝后的图片不能显示. 可能有些不同,我想试试吧.谢谢 !
    to: enmity(灵感之源)
    [email protected] 谢谢!
      

  19.   

    to tony_jian(神经质男主角) 我以前可以在CSDN上回答过拷贝文件就一句话
      

  20.   

    to tony_jian(神经质男主角) 我以前可能在CSDN上回答过拷贝文件就一句话
      

  21.   

    上面的代码显然有错, Buf 不能用string,应该用Byte最好。不信就用它试试拷一个含有汉字的TXT文件,都会有错!
      

  22.   

    agree with  enmity(灵感之源)
      

  23.   

    to :
    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
    进度条没反应
      

  24.   

    哈哈,你要给CPU点时间来处理重绘进度条哈。
    在适当的地方加个doevents试试。
      

  25.   

    我真是不明白,为什么要弄得那么辛苦,我这几天为我的毕业设计写了一个短小精悍的安装程序,如果要看效果作参考,留下email。文件拷贝进度“伪代码”如下:Private m_strFiles() As String
    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
      

  26.   

    TO  enmity(灵感之源)如果一个文件很大(100多MB)这种方法是很不准确的。
    其实直接用IO文件读写可以做到精确进度,只不过会牺牲很大的速度。
      

  27.   

    to:chice_wxg(我怕谁?我是谁!我是流氓我最贼。) 谁说直接使用IO文件读写会牺牲很大的速度?如果真的是那样,只能说明的你的能力还不够火候。我经过多次测试,使用IO直接操作文件,效率不比VB内置的函数差。
      

  28.   


    你用的什么办法?如果是 ReadFile/WriteFile 等API,那么你一个字节一个字节的读写,比1MB 1MB的读写慢很多。(我写过文件切割软件,多种办法都试过)如果用更底层的IO……我估计难度可想而知。
    而且,帖子我都看过了,我想好象没理解错   ^_^以上均为个人观点,欢迎指点。
      

  29.   

    我赞成chice_wxg(我怕谁?我是谁!我是流氓我最贼。) 的,enmity(灵感之源) 的并不准确。折中的话,可以先取所有要复制的文件的大小,再一个一个复制,每复制一个就根据已复制的字节数绘制进度条,而不要根据文件数量。当然也不绝对精确,但应该比enmity(灵感之源) 稍好一点点(只一点点而已),再加个计时器预计需要的时间也不错。
    代码就不写啦,就这个意思,你应该可以自己搞定的。