Option Explicit
'Module-level variable
Dim EndTime As Variant
Sub CopyNewFiles()
'Variables for source and
'destination files...
Dim SFile As String
Dim SPath As String
Dim DPath As String
'Set end time for initial run
If IsEmpty(EndTime) Then
EndTime = CDate(Now - TimeValue("01:00"))
End If
'Set source folder
'Change accordingly...
Const SFold As String = "C:\Users\gpeacock\Downloads\py3e_source\chapter03"
'Get first source filename
SFile = Dir(SFold & Application.PathSeparator & "*")
'If no source files, wait an hour
If SFile = vbNullString Then GoTo Wait
'Set destination folder
'Change accordingly...
Const DFold As String = "C:\Users\gpeacock\Desktop\destination_folder"
'Loop through source files and
'copy files created during last hour...
Do While SFile <> vbNullString
SPath = SFold & Application.PathSeparator & SFile
DPath = DFold & Application.PathSeparator & SFile
If FileDateTime(SPath) >= EndTime Then
FileCopy Source:=SPath, Destination:=DPath
End If
SFile = Dir
Loop
'Wait for one hour
'before running again...
Wait:
'set end time
EndTime = CDate(Now)
Application.OnTime _
EarliestTime:=Now + TimeValue("01:00"), _
Procedure:="CopyNewFiles"
End Sub