Imports System.IO
Public Class frmMain
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CopyFile("C:\test", "C:\test_2")
End Sub
Private Sub CopyFile(ByVal OldDirectory As String, ByVal NewDirectory As String)
Dim lst As New List(Of String)
For Each strFile As String In Directory.GetFiles(OldDirectory)
If lst.Count > 0 Then
Dim fInfo As New FileInfo(lst.Last)
Dim oInfo As New FileInfo(strFile)
Dim fTime As Date = fInfo.CreationTime
Dim oTime As Date = oInfo.CreationTime
Dim Dif As Integer = DateDiff(DateInterval.Second, fTime, oTime)
If Dif > 0 Then
lst.Clear()
lst.Add(strFile)
End If
Else
lst.Add(strFile)
End If
Next
Dim lFileInfo As New FileInfo(lst.Last)
File.Copy(lFileInfo.FullName, GetSlashPath(NewDirectory) & lFileInfo.Name, True)
End Sub
Private Function GetSlashPath(ByVal Path As String) As String
If Path.EndsWith("\") Then
Return Path
Else
Return Path & "\"
End If
End Function
End Class