Dim fos As New Scripting.FileSystemObject  '引用ms scripting runntime 库
Dim f As Scripting.File
Dim TFolder As Scripting.Folder
 '使用filesystemobject 对象拷贝,其文件对象可以直接访问文件的创建日期
    Set TFolder = fos.GetFolder(Text2.Text & "\")
    For Each f In TFolder.Files
        If f.DateCreated >= CDate(DTPicker1.Value) And f.DateCreated <= CDate(DTPicker2.Value) Then
           f.Copy Text1.Text & "\" & f.Name, True
        End If
    Next
   现在的问题是如何在f.Copy Text1.Text & "\" & f.Name, True前加个判断,只copy新的文件,对存放路径中已有的文件不进行copy,从而达到缩短copy时间的目的。

解决方案 »

  1.   

    Dim fos As New Scripting.FileSystemObject  '引用ms scripting runntime 库
    Dim f As Scripting.File
    Dim TFolder As Scripting.Folder
     '使用filesystemobject 对象拷贝,其文件对象可以直接访问文件的创建日期
        Set TFolder = fos.GetFolder(Text2.Text & "\")
        For Each f In TFolder.Files
            If f.DateCreated >= CDate(DTPicker1.Value) And f.DateCreated <= CDate(DTPicker2.Value) Then
               f.Copy Text1.Text & "\" & f.Name, False
            End If
        Next
      

  2.   

    复制前加个判断,看看目标文件是否存在即可.比如用dir判断:if dir(Text1.Text & "\" & f.Name)="" then f.Copy Text1.Text & "\" & f.Name, True也可以直接用错误处理语句跳过,就是加一句on error resume next,此时要使用f.Copy Text1.Text & "\" & f.Name,False
      

  3.   

    Dim fos As New Scripting.FileSystemObject  '引用ms scripting runntime 库
     Dim f As Scripting.File
     Dim TFolder As Scripting.Folder
    On Error Resume Next '←加这句再试试
      '使用filesystemobject 对象拷贝,其文件对象可以直接访问文件的创建日期
         Set TFolder = fos.GetFolder(Text2.Text & "\")
         For Each f In TFolder.Files
             If f.DateCreated >= CDate(DTPicker1.Value) And f.DateCreated <= CDate(DTPicker2.Value) Then
                f.Copy Text1.Text & "\" & f.Name, False
             End If
         Next