How to get the date created or modified from a file

1 post / 0 new
Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57
How to get the date created or modified from a file

I recently gave an intro course in IDEA and one of the participants wanted to know how to obtain the date and time of when a file was created so that they could add it to the file name in a script they were creating.  The functions doesn't exist within the IDEA basic keywords but it does exist within the objects that IDEA has access to, namely the Scripting.FileSystemObject which allows you to access all the information about a file.  So to obtain the date created or last modified you could use something like this:

Option Explicit

Sub Main
    Dim oFilebar As Object
    Dim oFSO As Object
    Dim oF As Object
    Dim strFileName As String
    'fist get a file
    Set oFilebar = CreateObject("ideaex.fileexplorer")
    oFilebar.displaydialog
    strFileName = oFilebar.selectedfile
    
    'obtain the file information
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set oF = oFSO.GetFile(strFileName)
    MsgBox oF.DateCreated
    MsgBox oF.DateLastModified
    
    Set oFilebar = Nothing
    Set oF= Nothing
    Set oFSO = Nothing
End Sub