Solved

VB Script to read latest file updated

Posted on 2013-11-20
2
251 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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

When you try to extract and to view the contents of a Microsoft Update Standalone Package (MSU) for Windows Vista, you cannot extract the files from the MSU. Here we are going to explain how to extract those hotfix details without using any third pa…
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 give you basic overview of the control panel section on Windows 7. It will depth in Network and Internet, Hardware and Sound, etc. This will be demonstrated using Windows 7 operating system.
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…

856 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