如何在路径中使用日期格式复制文件



我已经写了一个代码将文件复制到"当前日期"文件夹。因此,我想在文件路径中使用日期CopyData "E:From", "D:To & Format(Date, 'dd-mm-yyyy')& ''"如何可能?

我的代码如下:

Public Sub PerformCopy()
    MkDir "D:To" & Format(Date, "dd-mm-yyyy")
    CopyData "E:From", "D:To & Format(Date, 'dd-mm-yyyy')& ''"
End Sub
Public Sub CopyData(ByVal FromPath As String, ByVal ToPath As String)
Dim FSO As Object
Dim Fdate As Date
Dim FileInFromFolder As Object
Dim FolderInFromFolder As Object
    Set FSO = CreateObject("scripting.filesystemobject")
    'First loop through files
    For Each FileInFromFolder In FSO.getfolder(FromPath).Files
        Fdate = Int(FileInFromFolder.DateLastModified)
    If Fdate >= Date - 3 Then
        FileInFromFolder.Copy ToPath
    End If
    'Next loop throug folders
    For Each FolderInFromFolder In FSO.getfolder(FromPath).SubFolders
        CopyData FolderInFromFolder.Path, ToPath
    Next FolderInFromFolder
    Next
End Sub

您的代码

CopyData "E:From", "D:To & Format(Date, 'dd-mm-yyyy')& ''"

将两个参数传递给CopyData。第一个参数将是E:From,第二个参数为D:To & Format(Date, 'dd-mm-yyyy')& ''

如果将该代码更改为

CopyData "E:From", "D:To" & Format(Date, "dd-mm-yyyy") & ""

然后,传递的两个参数将为E:From,并且(假设今天是2016年12月31日)D:To31-12-2016,这是我相信您想要的。

相关内容

  • 没有找到相关文章

最新更新