CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
【经验总结】不能实施并行处理的情况 浅谈并行编程中的任务分解模式
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VB >  API

拷贝文件带进度条

楼主mylele()2006-02-11 01:43:09 在 VB / API 提问

先祝大家情人节快乐。  
  找CSDN找了好久了,   老是输入   msdn.net   怎么都进不来这里,  
  最后问人家才问到是csdn    
  已经解决了2年的东西都没解决好,从去年6月份,  
  找了N多资料都不行,没办法,不得不到这里来请教CSDN的高手了,人家说这里高手N多  
   
  小弟不废话了。再解决不了老板要抄我鱿鱼了  
  关于拷贝文件带进度的问题  
   
  现在目前这个是拷贝大型文件就很慢,局域网拷贝   平均速度也只有4MB左右,看到人家的有5-11MB,很是羡慕。  
  说明一下不是系统自代的拷贝  
   
  请求大家帮忙,给个代码谢谢 问题点数:100、回复次数:14Top

1 楼chenhui530(陈辉)回复于 2006-02-11 08:30:22 得分 0

你使用的是Winsock吧Top

2 楼chenhui530(陈辉)回复于 2006-02-11 08:30:38 得分 0

能看下你的代码吗Top

3 楼goodname008(卢培培,充电中......)回复于 2006-02-11 09:32:09 得分 0

一句话就是回调。  
  如果是下载文件,那恭喜楼主了,我刚写了个HTTP的:http://blog.csdn.net/goodname008/archive/2006/01/02/568668.aspx  
   
  文件复制的话就用   CopyFileEx   函数,都有回调接口的。Top

4 楼ZOU_SEAFARER(颓废程序员^_^)回复于 2006-02-11 10:35:32 得分 0

是不是可以利用命名管道来copy文件!!?Top

5 楼rainstormmaster(暴风雨 v2.0)回复于 2006-02-11 17:18:17 得分 0

无非就是打开文件,分段读写文件,同时设置滚动条的value,速度慢的话,应该是缓冲区分配得过小的原因,搜一下以前的帖子吧Top

6 楼mylele()回复于 2006-02-11 19:58:10 得分 0

我搜索了好多,大家帮忙解决一下吧。。拜托了~~Top

7 楼mylele()回复于 2006-02-11 20:00:56 得分 0

这个是我现在的代码,大家看看  
  速度很慢,特别是拷贝大型文件的时候  
  Option   Base   1       'VERY   IMPORTANT  
  Public   Event   CopyProgress(lngPercentDone   As   Long)  
  Public   Event   CopyError(strDescription   As   String)  
  Public   Event   CopyComplete()  
  Public   Event   CopyCancelled()  
  Private   bCancelAction   As   Boolean  
  Public   Sub   Cancel()  
          bCancelAction   =   True  
  End   Sub  
  Public   Function   CopyFile(strSource   As   String,   strDestination   As   String,   Optional   bOverwrite   As   Boolean   =   False,   Optional   intBufferSize   As   Integer   =   2048,   Optional   bSuppressErrors   As   Boolean   =   True)   As   Boolean  
          Dim   strError   As   String  
          Dim   BUFFER()   As   Byte  
          Dim   intSourceFile   As   Integer  
          Dim   intDestinationFile   As   Integer  
          If   strSource   =   ""   Then  
                  strError   =   "No   Source   File   Specified"  
          ElseIf   strDestination   =   ""   Then  
                  strError   =   "No   Destination   File   Specified"  
          ElseIf   Dir(strSource)   =   ""   Then  
                  strError   =   "Source   File   Does   Not   Exist"  
          End   If  
          If   strError   <>   ""   Then  
                  GoTo   copy_error  
          End   If  
          On   Error   Resume   Next  
          If   Dir(strDestination)   <>   ""   Then  
                  If   bOverwrite   Then  
                          Err.Clear  
                          If   (GetAttr(strDestination)   And   vbReadOnly)   =   vbReadOnly   Then  
                                  SetAttr   strDestination,   vbNormal  
                          End   If  
                          Kill   strDestination  
                                  If   Err.Number   <>   0   Then  
                                                  RaiseEvent   CopyError(Err.Description)  
                                          Exit   Function  
                                  End   If  
                  Else  
                          RaiseEvent   CopyError("Destination   file   exists")  
                   
                          Exit   Function  
                  End   If  
          End   If  
           
   
          intSourceFile   =   FreeFile  
          Open   strSource   For   Binary   Access   Read   Lock   Write   As   #intSourceFile  
          intDestinationFile   =   FreeFile  
          Open   strDestination   For   Binary   Access   Write   Lock   Write   As   #intDestinationFile  
          If   LOF(intSourceFile)   <   intBufferSize   Then  
                  ReDim   BUFFER(LOF(intSourceFile))  
          Else  
                  ReDim   BUFFER(intBufferSize)  
          End   If  
          While   Not   EOF(intSourceFile)   And   Loc(intSourceFile)   <>   LOF(intSourceFile)  
                  If   Loc(intSourceFile)   <>   LOF(intSourceFile)   Then  
                          If   LOF(intSourceFile)   -   Loc(intSourceFile)   <   intBufferSize   Then  
                                  ReDim   BUFFER(LOF(intSourceFile)   -   Loc(intSourceFile))  
                          End   If  
                  Else  
                          Erase   BUFFER  
                  End   If  
                  Get   #intSourceFile,   ,   BUFFER  
                  Put   #intDestinationFile,   ,   BUFFER  
                  BB&   =   BB&   +   intBufferSize   '累计字节大小  
                  If   timeGetTime   -   sysTime   >   1000   Then  
                          FrmMain.Label4.Caption   =   BB&   \   1024   \   1024   '显示拷贝速度  
                          sysTime   =   timeGetTime   '读取系统时间  
                          BB&   =   0   '清零拷贝字节数  
                  End   If  
                  '用户暂停  
                  While   FrmMain.暂停.Caption   =   "继续"  
                          If   FrmMain.停止.Enabled   =   False   Then   FrmMain.暂停.Caption   =   "暂停"  
                          DoEvents  
                  Wend  
                  RaiseEvent   CopyProgress(Loc(intSourceFile)   /   LOF(intSourceFile)   *   100)  
                  DoEvents  
                  If   bCancelAction   Then  
                          Close   intSourceFile  
                          Close   intDestinationFile  
                          Kill   strDestination  
                          bCancelAction   =   False  
                          RaiseEvent   CopyCancelled  
                          Exit   Function  
                  End   If  
          Wend  
          Close   intSourceFile  
          Close   intDestinationFile  
          RaiseEvent   CopyComplete  
          CopyFile   =   True  
  Exit   Function  
  copy_error:  
          RaiseEvent   CopyError(strError)  
          Exit   Function  
  End   Function  
  Top

8 楼rainstormmaster(暴风雨 v2.0)回复于 2006-02-11 21:00:13 得分 20

intBufferSize可以大一些,你现在一次才分配2k的缓冲区,肯定是慢Top

9 楼mylele()回复于 2006-02-11 21:08:32 得分 0

但是调用的时候设置缓存呀  
  CopyFile(strSource   As   String,   strDestination   As   String,   Optional   bOverwrite   As   Boolean   =   False,   Optional   intBufferSize   As   Integer   =   2048,   Optional   bSuppressErrors   As   Boolean   =   True)   As   Boolean  
   
  调用的时候是这样  
  CopyFile   "d:\abc.exe","d:\abcdddd.exe",true,8129,trueTop

10 楼NewViewStudio(傻鱼)回复于 2006-02-11 22:31:59 得分 50

方法1:增大缓冲  
          机器=P4   2.4M 512M   DDR  
          文件长度=701M  
   
          缓冲长度=8K  
          用时=88.063s  
   
          缓冲长度=64K  
          用时=85.797s  
   
  方法2:  
          如果是针对网络的拷贝,那么你应该利用WINSOCK多端口分段拷贝法,那样可以利用你机器的最大资源来进行拷贝,一般如果是远程拷贝至少开128个端口分段拷贝,如果是局域网的话一般16个端口就OK了。Top

11 楼NewViewStudio(傻鱼)回复于 2006-02-11 22:33:44 得分 30

对楼上资料的更改  
   
  我的机器是P4   2.4G  
   
  不好意思Top

12 楼mylele()回复于 2006-02-12 00:27:19 得分 0

NewViewStudio(傻鱼)  
  请问您能加我QQ吗?   701365  
  我的是局域网拷贝~  
  WINSOCK多端口分段拷贝法   这个我还不明白啊Top

13 楼mylele()回复于 2006-02-12 15:54:29 得分 0

急啊Top

14 楼NewViewStudio(傻鱼)回复于 2006-02-21 00:23:37 得分 0

前几天我工作比较忙,所以没有功夫来这,今天刚看到,我已经向你的QQ发送邀请了Top

相关问题

  • 拷贝文件时,如何得到拷贝进度?
  • 如何实现WINDOWS风格的文件拷贝功能?(显示拷贝进度)
  • InstallShield v6.22中如何显示拷贝文件的进度条?
  • 如何如实地反应文件拷贝进度?
  • 拷贝文件时,如何监控进度?
  • vb6拷贝文件如何实现进度条
  • 在程序中拷贝文件,怎样显示出explorer的拷贝文件的进度对话框?
  • 谁能告诉我当拷贝文件时,显示的进度条是如何知道文件拷贝的进度的?
  • vc中能否调用windows中拷贝文件的那个进度条?
  • 拷贝文件时能否调用系统的那个对话框(显示拷贝进度的)??

关键词

  • .net
  • 拷贝
  • 文件
  • 代码
  • 解决
  • csdn
  • intsourcefile
  • strdestination
  • intdestinationfile
  • bcancelaction

得分解答快速导航

  • 帖主:mylele
  • rainstormmaster
  • NewViewStudio
  • NewViewStudio

相关链接

  • Visual Basic类图书
  • Visual Basic类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
惹火投票。。火热进行中...
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
CSDN网站24小时值班电话:13552009689
Copyright © 2000-2009, CSDN.NET, All Rights Reserved
GongshangLogo