如何在复制文件的路径中使用日期格式
How to use date format in a path to copy files
我写了一个代码来将文件复制到 "current date" 文件夹。所以,我想在文件路径中使用日期 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:\To-12-2016\
,我相信这就是你想要的。
我写了一个代码来将文件复制到 "current date" 文件夹。所以,我想在文件路径中使用日期 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:\To-12-2016\
,我相信这就是你想要的。