How do I retrieve an external file's attribute

I wish to programatically retrieve the date created and last modified on an external file.

With VBA on a Windows system I can write code like:


Sub GetDateCreated()

Dim oFS As Object
Dim strFilename As String

'Put your filename here
strFilename = "c:\excel stuff\commandbar info.xls"

'This creates an instance of the MS Scripting Runtime FileSystemObject class
Set oFS = CreateObject("Scripting.FileSystemObject")

MsgBox strFilename & " was created on " & oFS.GetFile(strFilename).DateCreated

Set oFS = Nothing

End Sub


But of course on a Apple or Linux system the create object statement will will not work.

Can anyone tell me what I need to do in order to make this work with LO?


from os import path
from time import ctime

def get_creation_timestamp( some_path ): 
    print( ctime( path.getctime( some_path )))

see .path.getctime



Thank you.
I’ve also discovered the the VBA function


also works in LO

Hi - FYI This function was bug (see tdf # 63306) in some intermediate versions of LibreOffice. The API overcomes the bug and also offers other powerful file access functions. Example:

sub LibODateTime
dim oSFA as object
dim oDateFile as new
dim sUrl as string
sUrl = "c:\test.odt"
oSFA = createUnoService("")
oDateFile = oSFA.getDateTimeModified(convertToURL(sUrl))
with oDateFile
        print format(.day, "00\/") & format(.month, "00\/") & .year &_
                 format(.hours, "\ 00\:") & format(.minutes, "00\:") & format(.seconds, "00")
end with
end sub

the Truth is: the whole Basic is an ancient bug, lets compare your print format concationation with the String formatting properties in python:

print("{ts.Year:d}-{ts.Month:02d}-{ts.Day:02d} "