Solved

VB Script to read latest file updated

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Lee
Windows 7 Ultimate and Enterprise (and 2008 R2) introduced a new feature you may not be aware of - Boot from VHD.   Boot from VHD (or what Microsoft refers to asNative Boot allows you to install Windows to a VHD (Virtual Hard Disk) file that is t…
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.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.

679 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