Results 1 to 2 of 2

Thread: Most Recently Modified

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    49

    Most Recently Modified

    How would I go about copying the most recently modified file in a specific directory to another directory with the click of a button?

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Most Recently Modified

    VB Code:
    1. Private Const PATHTO As String = "C:\Test\" 'Put path to where you want it to go....
    2. Private Const PATHFROM As String = "C:\" 'Path From
    3. Private Function CopyMostRecent()
    4.  
    5. Dim FSO As New FileSystemObject
    6. Dim FLDR As Folder
    7. Dim FileName As FILE
    8. Dim CurrentNewestFileName As String
    9. Dim NewestDate As Date
    10.  
    11. Set FLDR = FSO.GetFolder(PATHFROM)
    12. ReStart:
    13. For Each FileName In FLDR.Files
    14.     If FileName.DateLastModified > NewestDate Then
    15.         NewestDate = FileName.DateLastModified
    16.         CurrentNewestFileName = FileName.Name
    17.         GoTo ReStart
    18.     End If
    19. Next
    20. Set FileName = FLDR.Files(CurrentNewestFileName)
    21.  
    22. FileName.Copy PATHTO, True
    23.  
    24. End Function
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width