Solved

VB Script to read latest file updated

Posted on 2013-11-20
2
247 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 500 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I hope this helps those who have been battling the SanDisk / U3 problem for a while. For anyone that is running Windows 7 64bit and is receiving and searching the internet for the “Windows Error: Windows has allocated a drive letter to the U3 dri…
One of the features I've come to appreciate about Windows 7 and Windows Server 2008 R2 is the ability to pin applications to the task bar. As useful a feature as I've found this, it does have some quirks.  For example, have you ever tried pinning an…
This Micro Tutorial will go in depth within Systems and Security in Windows 7 and will go into detail regarding Action Center, Windows Firewall, System, etc. This will be demonstrated using Windows 7 operating system.
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now