I have written a code to copy files to "current date" folder. So, I want to use date in file path CopyData "E:\From\", "D:\To\ & Format(Date, 'dd-mm-yyyy')& '\'"
How is it possible?.
My code is below:
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
Your code
is passing two parameters to
CopyData
. The first parameter will beE:\From\
and the second parameter will beD:\To\ & Format(Date, 'dd-mm-yyyy')& '\'
.If you change that code to be
then the two parameters passed will be
E:\From\
and (assuming today is 31 December 2016)D:\To\31-12-2016\
, which is what I believe you want.