Solved

VB Script to read latest file updated

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
acrobat scan error 4 44
SQL Server error 26 102
copying drivers in MDT 7 30
How to open a zip file 4 60
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.
While working, an annoying popup showing below will come and we cannot cancel or close it form the screen. The error message will come again and again.
This Micro Tutorial will teach you the basics of configuring your computer to improve its speed. It will also teach you how to disable programs that are running in the background simultaneously. This will be demonstrated using Windows 7 operating…
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

932 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

10 Experts available now in Live!

Get 1:1 Help Now