Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB Script to read latest file updated

Posted on 2013-11-20
2
Medium Priority
?
259 Views
Last Modified: 2013-11-21
Hi,

I have a folder as c:/temp
in temp folder I have files created at different time stamp for example file1.txt is created @ 11:05:10 and another file2.txt created @ 11:06:03 and file3.txt created @ 11:07:04.

I need to write a vb script that can check the latest time stamp file from the c:/temp folder and provide me the name of the latest file.txt name.

for example file3.txt is latest updated @ 11:07:04 so VB script will display the name as file3.txt
0
Comment
Question by:theology
2 Comments
 
LVL 9

Accepted Solution

by:
Beartlaoi earned 2000 total points
ID: 39663356
There are actually three timestamps on a file, this one will get them all.
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFS.GetFolder("C:\temp")
dtLatestCreated = DateSerial(1900,1,1)
sLatestCreated = ""
dtLatestAccessed = DateSerial(1900,1,1)
sLatestAccessed = ""
dtLatestModified = DateSerial(1900,1,1)
sLatestModified = ""
For Each oFile in oFolder.Files
	iExtPos = InStrRev(oFile.Name, ".")
	If LCase(Mid(oFile.Name, iExtPos + 1)) = "txt" Then
		If oFile.DateCreated > dtLatestCreated Then 
			dtLatestCreated = oFile.DateCreated
			sLatestCreated = oFile.Name
		End If
		If oFile.DateLastAccessed > dtLatestAccessed Then 
			dtLatestAccessed = oFile.DateLastAccessed
			sLatestAccessed = oFile.Name
		End If
		If oFile.DateLastModified > dtLatestModified Then 
			dtLatestModified = oFile.DateLastModified
			sLatestModified = oFile.Name
		End If
	End If
Next
WScript.Echo "LatestCreated  " & dtLatestCreated & " " & sLatestCreated
WScript.Echo "LatestAccessed " & dtLatestAccessed & " " & sLatestAccessed
WScript.Echo "LatestModified " & dtLatestModified & " " & sLatestModified

Open in new window

0
 

Author Closing Comment

by:theology
ID: 39666192
Thank you so much it works !!!!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

By default the complete memory dump option is disabled in windows . If we want to enable the complete memory dump for a diagnostic purpose, we have a solution for it. here we are using the registry method to enable this.
A quick guide on how to use Group Policy to create a custom power plan and set it active on Windows 7.
In this Micro Tutorial viewers will learn how to use Boot Corrector from Paragon Rescue Kit Free to identify and fix the boot problems of Windows 7/8/2012R2 etc. As an example is used Windows 2012R2 which lost its active partition flag (often happen…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
Suggested Courses

916 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