[Solved] last change time of file

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
stievy
Posts: 2
Joined: Thu Jun 26, 2008 11:06 am

[Solved] last change time of file

Post by stievy »

Hi,

I'm looking for a way in OOo basic to check when a file is last changed (modified).
I know there is a function like this in php, but I don't know if there is one in OOo basic...

I want to create a function like this in php, but then in OOo basic:
$file1=x:\test\test.doc;
$file2=c:\test.doc;
$file1modified = date("F d Y H:i:s.", filectime($file1);
$file2modified = date("F d Y H:i:s.", filectime($file2);

if ($file1modified > file2modified){
//copy it to c:\
}

But like I said, I don't know if there is a function for in OOo like the filectime-function in php... :P

The OOo version i'm using is 2.0.4.17 (No I'm not able to upgrade it, cause it's installed on my work and we can't install another version)

Thx 4 any help!

Greetz
Stievy
Last edited by stievy on Tue Jul 01, 2008 10:09 am, edited 2 times in total.
OOo 2.0.X on Ms Windows W2k + Novell Suse 10 (Linux)
User avatar
probe1
Volunteer
Posts: 277
Joined: Mon Oct 08, 2007 1:34 am
Location: Chonburi Thailand

Re: last change time of file

Post by probe1 »

Check the DocumentInfo,

something like this:

Code: Select all

If ThisComponent.hasURL() Then
  With ThisComponent.DocumentInfo
  If .ModifiedBy <> "" Then
     msgbox "Document last changed " & .ModifyDate.Year & "-" & .ModifyDate.Month & "-" & .ModifyDate.Day
  Else
     msgbox "Document created " & .CreationDate.Year & "-" .CreationDate.Month & "-" & .CreationDate.Day
  End If
  End With
Else 
 msgbox "Document was not saved by now"
End If
Cheers
Winfried

DateTime2 extension: insert date, time or timestamp, formatted to your needs
stievy
Posts: 2
Joined: Thu Jun 26, 2008 11:06 am

Re: last change time of file

Post by stievy »

Thx :)

Ok this is what I made from it:

Code: Select all

Function checkVersion (localurl,serverurl)
	Dim Dummy()
	Dim localFileModifiedDate as String
	Dim remoteFileModifiedDate as String
	Dim localFileModifiedTime as String
	Dim remoteFileModifiedTime as String
	
	localdoc = StarDesktop.LoadComponentFromUrl(localurl,"MyFrame",0,Dummy)
	With localdoc.DocumentInfo.ModifyDate
		localFileModifiedDate = .Year & "-" & Format(.Month,"0#") & "-" & Format(.Day,"0#")
		localFileModifiedTime = Format(.Hours,"0#") & ":"  & Format(.Minutes,"0#")  & ":"  & Format(.Seconds,"0#")
	End With
	localdoc.close(true)
	
	ServerDoc = StarDesktop.LoadComponentFromUrl(serverurl,"MyFrame",0,Dummy)
	With ServerDoc.DocumentInfo.ModifyDate
		remoteFileModifiedDate = .Year & "-" & Format(.Month,"0#") & "-" & Format(.Day,"0#")
		remoteFileModifiedTime = Format(.Hours,"0#") & ":"  & Format(.Minutes,"0#")  & ":"  & Format(.Seconds,"0#")
	End With
	ServerDoc.close(true)
	
	If (localFileModifiedDate < remoteFileModifiedDate) Then
		'copy it, file on server is newer
	Else
		If ((localFileModifiedDate = remoteFileModifiedDate) And (localFileModifiedTime < remoteFileModifiedTime)) Then
			'copy it, changed the same day
		Else
			'do nothing, file up to date
			Exit Function
		End if
	End If
End Function
Greetz
Stievy
OOo 2.0.X on Ms Windows W2k + Novell Suse 10 (Linux)
Post Reply