Ask Your Question

how do I retrieve an external file's attribute

asked 2015-04-10 10:40:10 +0200

jay Arr gravatar image

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?

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted

answered 2015-04-11 08:01:29 +0200

pierre-yves samyn gravatar image

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
edit flag offensive delete link more


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} "
karolus gravatar imagekarolus ( 2015-04-11 09:31:57 +0200 )edit

answered 2015-04-10 11:30:29 +0200

karolus gravatar image


from os import path
from time import ctime

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

see .path.getctime



edit flag offensive delete link more

answered 2015-04-10 11:47:11 +0200

jay Arr gravatar image

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


also works in LO

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2015-04-10 10:40:10 +0200

Seen: 524 times

Last updated: Apr 11 '15