How would I go about copying the most recently modified file in a specific directory to another directory with the click of a button?
Printable View
How would I go about copying the most recently modified file in a specific directory to another directory with the click of a button?
VB Code:
Private Const PATHTO As String = "C:\Test\" 'Put path to where you want it to go.... Private Const PATHFROM As String = "C:\" 'Path From Private Function CopyMostRecent() Dim FSO As New FileSystemObject Dim FLDR As Folder Dim FileName As FILE Dim CurrentNewestFileName As String Dim NewestDate As Date Set FLDR = FSO.GetFolder(PATHFROM) ReStart: For Each FileName In FLDR.Files If FileName.DateLastModified > NewestDate Then NewestDate = FileName.DateLastModified CurrentNewestFileName = FileName.Name GoTo ReStart End If Next Set FileName = FLDR.Files(CurrentNewestFileName) FileName.Copy PATHTO, True End Function