How to Get Created Date And Time Of a Particular File in QTP or In VBScrit?

0
55
Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Date in Vbscript

How to Get Created Date And Time Of a Particular File in QTP or In VBScript?

  • How to get created date and time of a particular file?
  • How to get last Modified date and time of a particular file?
  • How to get last accessed date and time of a particular file?

Here is the code using VBscript’s FSO.

Set f1 = CreateObject("Scripting.FileSystemObject")
msgbox "created reference to first file object"
Set f2 = f1.GetFile("E:fak.txt")
S = "File was Created on: "&f2.DateCreated
Msgbox SOutput->File was Created on: 10/12/2008 3:45:16 PM
Set f1 = CreateObject("Scripting.FileSystemObject")
msgbox "created reference to first file object"
Set f2 = f1.GetFile("E:Lak.txt")S = "File was Last Modified on: "&f2.Datelastmodified
Msgbox SOutput->File was Last Modified on: 10/12/2008 3:51:24 PM
Set f1 = CreateObject("Scripting.FileSystemObject")
msgbox "created reference to first file object"
Set f2 = f1.GetFile("E:fak.txt")S = "File was Last Accessed on: "&f2.Datelastaccessed
Msgbox SOutput->File was Last Accessed on: 10/12/2008 3:55:15 PM

Another one is given in StackOverflow here:


Option Explicit  
Dim Myfso, path, file, LatestDate, LatestFile
Set Myfso= CreateObject("Scripting.FileSystemObject")
msgbox "created reference to first file object"
Set LatestFile= Nothing
For Each file in Myfso.GetFolder("E:Temp").Files
  If (LatestFileis Nothing) Then
    Set LatestFile= file
  ElseIf (file.DateLastModified > LatestFile.DateLastModified) Then
    Set recentFile = file
  End If
Next

If LatestFile is Nothing Then
msgbox  "no latest files"
Else
msgbox "Latest file is " & LatestFile.Name & " " & LatestFile.DateLastModified
End If

Similar kind of solution is given here also:


Dim Myobj, Myobj1
Set Myobj= CreateObject("Scripting.FileSystemObject")
msgbox "created reference to first file object"
Set Myobj1=obj.GetFile("C:Usersabc.vbs") 
Msgbox "ParentFolder of File is "& Myobj1. ParentFolder
Msgbox "Path of File is "& Myobj1. Path
Msgbox "Size of File is "& Myobj1. Size
Msgbox "Type of File is "& Myobj1. Type
Msgbox "DateCreated of File is "& Myobj1.DateCreated 
Msgbox "Attributes of File is "& Myobj1.Attributes
Msgbox "DateLastAccessed of File is "& Myobj1.DateLastAccessed
Msgbox "DateLastModified of File is "& Myobj1.DateLastModified
Msgbox "Name of File is" & Myobj1.Name 
Msgbox "Drive of File is "& Myobj1.Drive 

Myobj1.Delete
Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

LEAVE A REPLY

Please enter your comment!
Please enter your name here