Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7433849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:44:17+00:00 2026-05-29T09:44:17+00:00

How could I modify this VBScript to return only the newest file’s name and

  • 0

How could I modify this VBScript to return only the newest file’s name and Last Modified date? Currently it returns anything modified in the last 24 hours. I want to look for the most recent file only. I borrowed this from StackOverflow, not yet a VBScript wizard.

option explicit  
dim fileSystem, folder, file
dim path   
path = "C:\test"  
Set fileSystem = CreateObject("Scripting.FileSystemObject") 
Set folder = fileSystem.GetFolder(path) 
for each file in folder.Files         
if file.DateLastModified > dateadd("h", -24, Now) then         
'whatever you want to do to process'         
WScript.Echo file.Name & " last modified at " & file.DateLastModified     
end if
next 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:44:18+00:00Added an answer on May 29, 2026 at 9:44 am

    For working with files on VBScript it is recommended you use the FileSystemObject.

    The FileSystemObject has the following feature’s that help you solve your problem:

    • FileSystemObject.GetFolder – Returns a Folder object corresponding to the folder in a specified path.
    • Folder.Files – Returns a Files collection consisting of all File objects contained in the specified folder.
    • File.DateLastModified – Returns the date and time that the specified file or folder was last modified.

    To demonstrate, I have supplied an implementation of GetRecentFile (and GetRecentFolder) which scans the supplied input path and determines the most recent file by finding the file that has the greatest DateLastModified property.

    Option Explicit  
    
    Function GetRecentFile(path)
      Dim fso, file
      Set fso = CreateObject("Scripting.FileSystemObject")
      Set GetRecentFile = Nothing
      For Each file in fso.GetFolder(path).Files
        If GetRecentFile is Nothing Then
          Set GetRecentFile = file
        ElseIf file.DateLastModified > GetRecentFile.DateLastModified Then
          Set GetRecentFile = file
        End If
      Next
    End Function
    
    Function GetRecentFolder(path)
      Dim fso, folder
      Set fso = CreateObject("Scripting.FileSystemObject")
      Set GetRecentFolder = Nothing
      For Each folder in fso.GetFolder(path).SubFolders
        If GetRecentFolder is Nothing Then
          Set GetRecentFolder = folder
        ElseIf folder.DateLastModified > GetRecentFolder.DateLastModified Then
          Set GetRecentFolder = folder
        End If
      Next
    End Function
    
    Dim recentFile
    Set recentFile = GetRecentFolder("C:\Temp")
    If recentFile is Nothing Then
      WScript.Echo "No recent files found"
    Else
      WScript.Echo "Recent file is " & recentFile.Name & " " & recentFile.DateLastModified
    End If
    

    References:

    • https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/filesystemobject-object
    • https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/getfolder-method
    • https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/files-property
    • https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/datelastmodified-property
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could somebody please name a few. I could given time, but this is for
How to modify this function so it could add target=_blank attribute to external links?
I was wondering how I could modify this code so that it has a
Is there a common interface in Python that I could derive from to modify
Could somebody please do a rundown of how to programmatically encrypt a config-file in
I've been trying to modify this method from redirecting and returning the contents of
The following code sample shows how to serialize/deserialize to a file. How could I
I'm trying to modify this code in an attempt to make it work on
So I've read you should use POST for anything that could modify data. E.g.
The following code lies within cellForRowAtIndexPath . 1.) i need to modify this code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.