Kill with multiple files

Version: 7.5.7.1 (X86_64) / LibreOffice Community
Build ID: 47eb0cf7efbacdee9b19ae25d6752381ede23126
CPU threads: 4; OS: Linux 5.15; UI render: default; VCL: gtk3
Locale: pt-BR (pt_BR.UTF-8); UI: pt-BR
Calc: threaded

I’m using Kill in one of my DB macros, in order to delete the current image in the register in its folder, it is working well, but now I need it to delete multiple images that contain the same id on the name. Im naming them something like "car1.photo1 ; car1.photo2 ; and so go on. I would like a way that I could use kill to delete all the photos that start like “car1”. Somehing that look like this:

Kill "C:\Users\ThisUser\Folder\car1*"

And then it would delete all of the files in Folder that starts with car1 not worrying about whats after it.

hallo

from pathlib import Path

def kill_cars(*_):
    for p in Path("C:/Users/ThisUser/Folder/").glob("car1*"):
        p.unlink()

In BASIC it’s not much more complicated:

Sub KillByMask(sFolderName As String, sMaskToDelete As String)
Dim aFiles As Variant, i As Long, sFileName As String
	GlobalScope.BasicLibraries.LoadLibrary("Tools")
	aFiles = ReadDirectories(sFolderName, False, False, False)
	For i = LBound(aFiles) To UBound(aFiles)
		sFileName = ConvertFromURL(aFiles(i)(0))
		If InStr(sFileName, sMaskToDelete) Then Kill sFileName
	Next i
End Sub

and call it like this

Sub TestKill()
	KillByMask("C:\Users\ThisUser\Folder\", "\car1")
End Sub
2 Likes