vb怎么实现文件的拷贝,怎么实现文件夹的拷贝?我想把从c:\ss.txt拷贝到d:\mm.txt下怎么实现,还有怎么拷贝文件夹,我不懂vb但现在要求用vb做一拷贝文件的界面,
还要一状态条显示文件拷贝的进度,请帮帮忙

解决方案 »

  1.   

    VB的FileCopy函数无法知道拷贝了多少字节,进度条的Value无法知道。
    API函数SHFileOperation,这个函数可以实现拷贝功能,同时还可以显示带有进度条的标准动画对话框。该函数的使用可以参考微软的Knowledge Base的文章:“Q151799 OWTO: Use the Animated Copy Functions in Windows 95/98”。 但是它要打开自己的窗口,如果希望的是把进度条嵌入到自己的窗口中,可以这么写。自己填加processbar Public Function CopyFile(Src As String, Dst As String) As Single
         Dim BTest!, FSize!
         Dim F1%, F2%
         Dim sArray() As Byte
         Dim buff As Integer
         
         Const BUFSIZE = 1024
         
         buff = 1024
         
         F1 = FreeFile
         Open Src For Binary As F1
         F2 = FreeFile
         Open Dst For Binary As F2
         
         FSize = LOF(F1)
         BTest = FSize - LOF(F2)
         ReDim sArray(BUFSIZE) As Byte
         
         Do
         If BTest < BUFSIZE Then
         buff = BTest
         ReDim sArray(buff) As Byte
         End If
         
         Get F1, , sArray
         Put F2, , sArray
         
         BTest = FSize - LOF(F2)
         If BTest < 0 Then
         ProgressBar.Value = 100
         Else
         ProgressBar.Value = (100 - Int(100 * BTest / FSize))
         End If
         Loop Until BTest <= 0
         
         Close F1
         Close F2
         CopyFile = FSize
         
        End Function
      

  2.   

    VB的FileCopy函数无法知道拷贝了多少字节,进度条的Value无法知道。
    API函数SHFileOperation,这个函数可以实现拷贝功能,同时还可以显示带有进度条的标准动画对话框。该函数的使用可以参考微软的Knowledge Base的文章:“Q151799 OWTO: Use the Animated Copy Functions in Windows 95/98”。(网址:http://support.microsoft.com/kb/q151799/) 但是它要打开自己的窗口,如果希望的是把进度条嵌入到自己的窗口中,可以这么写。自己填加processbar Public Function CopyFile(Src As String, Dst As String) As Single
         Dim BTest!, FSize!
         Dim F1%, F2%
         Dim sArray() As Byte
         Dim buff As Integer
         
         Const BUFSIZE = 1024
         
         buff = 1024
         
         F1 = FreeFile
         Open Src For Binary As F1
         F2 = FreeFile
         Open Dst For Binary As F2
         
         FSize = LOF(F1)
         BTest = FSize - LOF(F2)
         ReDim sArray(BUFSIZE) As Byte
         
         Do
         If BTest < BUFSIZE Then
         buff = BTest
         ReDim sArray(buff) As Byte
         End If
         
         Get F1, , sArray
         Put F2, , sArray
         
         BTest = FSize - LOF(F2)
         If BTest < 0 Then
         ProgressBar.Value = 100
         Else
         ProgressBar.Value = (100 - Int(100 * BTest / FSize))
         End If
         Loop Until BTest <= 0
         
         Close F1
         Close F2
         CopyFile = FSize
         
        End Function
      

  3.   

    1、添加引用microsoft scripting runtime
    方法:选择菜单“工程”-->“引用”-->选择“microsoft scripting runtime”2、使用方法
    Option ExplicitPrivate Sub Form_Load()
    Dim FileSys As New FileSystemObject
    Dim FolderObj As Folder
    Set FileSys = CreateObject("scripting.filesystemobject")
    FileSys.CopyFile "c:\ss.txt", "d:\mm.txt", True '拷贝文件
    FileSys.CopyFolder "c:\1", "d:\2", True     '拷贝文件夹
    End Sub
      

  4.   

    用FileCopy
    自己做一个进度条就是了,既好看又适用。
      

  5.   

    方法好多,filesystemobject(scrrun.dll),还有api,以及sh打头的api,进度条,文件存在覆盖询问等都有,不需要你自己写。