How to delete a backup using a variable and wildcard?

Win10 LO7.1.2.2 HSQL2.51

Hi,

I have a backup routine where one specifies the destination via a textbox, once the button is clicked the backup is generated locally or on a mapped network drive or usb.

image description

image description

All working fine. However I only want to retain the last backup and as such need to delete the previous one.
Thats were I am stuck as a- the path is a variable and b- the filename is timestamped.

Any thoughts how I can clear an existing backup before creating a new one? The backups subfolder may contain backups of different databases all having a prefix before the timestamp.

If not FileExists(sPathURL) Then      
     Msgbox "specified drive or destination not connected " 
     exit sub
     end if
   sPath = ConvertFromURL(sPathURL)
   sName = ThisDatabaseDocument.Title
   iLen = InStr(sPath, sName)

rem sPath = Left(sPath, iLen-1)
strSQL = "BACKUP DATABASE TO " & “’” & sPath & “” & “Backups’ BLOCKING NOT COMPRESSED”
oConnection = oDoc.CurrentController.ActiveConnection
oStmt = oConnection.createStatement()
oStmt.execute(strSQL)
Dim sVar as Integer
sVar = MsgBox(“Respaldado con éxito” ,64,“MPQ”)
Call lbu()

thanks

Hello,

Deleting in the known (current) folder is not difficult. This is just string functions. The part I can’t see being accomplished is if it was previously stored in a different directory. How would one know?

Hello @Herr Ratslinger , thanks for the swift response.
re string function can I incorporate something like Left x characters into the following ?

Dim oSimpleFileAccess
Dim oToFile
Dim oToURL
oSimpleFileAccess = createUnoService(“com.sun.star.ucb.SimpleFileAccess”)
oToFile = sPath & “” & “Backups”
oToURL = ConvertToUrl(oToFile)
If oSimpleFileAccess.exists(oToURL) then
oSimpleFileAccess.kill(oToURL)
End If

This code just empties the entire backup folder

@Ratslinger re folder change I guess one could possibly get the current value from the textbox on receiving focus and kill the folder if the text changed event occurs.

@gkick,

Since you have a mixture of files you need care in finding the correct files(s) to delete. In this post → Suggeston for Location of Backup Files, at the very end of my answer is a document with code. Starting near the bottom of page #8 to the end is a routine to extract, sort and delete files exceeding X number.

See if that helps.

@gkick,

Your folder change comment does not seem valid. Can’t see how that is a trusted source.

Thank you,will check it out