Solved

VBScript

Posted on 2011-09-14
1
467 Views
Last Modified: 2012-05-12
Experts,

I need a vbscript that will return the file name of the latest date modified file within a folder.

For example 3 files in folder:

test1.xls          4/3/2011
test2.xls          4/1/2009
test3.xls          5/3/2001

I need it to return  test1.xls

Any ideas?

Thanks.
Dim objFSO, filename, strFiles, objFile
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objSelectedFolder = objFSO.GetFolder("c:\temp\")

    Set colFiles = objSelectedFolder.Files
    For Each objFile In colFiles
        strFiles = objFile.name
      end if
    Next
filename =  strFiles

Open in new window

0
Comment
Question by:asmyatt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 38

Accepted Solution

by:
Gerwin Jansen, EE MVE earned 500 total points
ID: 36539654
Hello, you can try this:

Set objFSO = CreateObject("Scripting.FileSystemObject")

SearchFolder = "c:\temp\"
Set objFolder = objFSO.GetFolder(SearchFolder)

NewestFile = ""
NewestDate = #1/1/1970#

For Each objFile In objFolder.Files
    If objFile.DateLastModified > NewestDate Then
        NewestDate = objFile.DateLastModified
        NewestFile = objFile.Name
    End If
Next

WScript.Echo NewestFile

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question