How do I delete actually opened text file using only LibreOffice options? Or another simple way

For example:

  1. I found some forgotten text file in some forgotten folder.
  2. I opened this file.
  3. I saw, that it’s unusual file and I want to delete it! I want put it in the Trash folder, but I cannot find this option in LibreOffice.

Now I had to close the document and go to folder, search exactly this file. It takes some time for searching forgotten file in forgotten folder. I want to find an option for deleting of actually opened file.

If you found some forgotten text file in some forgotten folder, then you used Windows explorer or “Open…” (Ctrl+O) menu item in LibO for that. In both cases you can use popup menu with right mouse button click to delete that file (even to trash folder). What’s the problem?
– I want to find an option for deleting of actually opened file.
If file is opened, it could not be deleted. First of all you must close file, and only after that you can delete it.

First of all you must close file, and only after that you can delete it.

Thanks for your answer

Such a functionality will not be added to a standard installation for obvious reasons - the user would be much too likely kill his valuable documents… But it easy to add that functionality by adding a little Macro.

' closes and deletes the currently active document
' don't use it unless you're OK loosing all your data
' this macro comes with no warrenty whatsoever.
' ALWAYS HAVE A BACKUP
Sub closeAndDelete
	Dim fileurl as String
	Dim answer as Integer
	oDoc = ThisComponent
	If oDoc.hasLocation() Then
		fileurl = oDoc.getLocation()
		If FileExists(fileurl) Then
			answer = msgBox("Do you really want to delete the file"+Chr$(13)+ _
							"»"+fileurl+"« ?", 4+48+256, "Confirm deletion")
			If answer = 6 Then
				' user asked for it, so kill it with fire...
				oDoc.close(true)
				Kill(fileurl)
			EndIf
		Else
			msgBox("Error - file "+Chr$(13)+"»"+fileurl+"« does not exist?", 0)
			exit Sub
		EndIf
	Else
		' document wasn't saved, just close the document
		If oDoc.isModified() Then
			answer = msgBox("Do you really want to throw away your changes?",4+48+256)
			If answer <> 6 Then
				' abort if answer is not yes
				exit Sub
			EndIf
		EndIf
		oDoc.close(true)
	EndIf
End Sub

To add it, choose Tools | Macros → Organize → LibreOffice Basic and select Module1 below “My Macros” (or create a seperate module if you wish) and choose Edit and copy’n’paste the above macro into the editor and hit the save button.

To assign that macro to a keyboard shortcut, menu entry or toolbar button, go to **Tools | Customize ** and select the appropriate section (menu, shortcut or toolbar) to add it. You’ll find the Macros at the very bottom in the command/function selection area.

I have to revise and to merge hundreds of documents (all too often obsolete or redundant) – this macro makes it much easier … :slight_smile:

Very nice. Thanks. Exactly what I want, but I won’t use this option because I afraid of risk. But you give very good advice.

No, deleting a file is the job of your file manager, not the job of an application software.

Thank you, your answer was very useful for me. Now I know, that deleting of the files is the job of some file manager, not the job of LibreOffice or another application software. Thanks.