* fhFileUtils not using Recycle Bin

For users to report plugin bugs and request plugin enhancements; and for authors to test new/new versions of plugins, and to discuss plugin development (in the Programming Technicalities sub-forum). If you want advice on choosing or using a plugin, please ask in General Usage or an appropriate sub-forum.
Post Reply
User avatar
Mark1834
Megastar
Posts: 2147
Joined: 27 Oct 2017 19:33
Family Historian: V7
Location: South Cheshire, UK

fhFileUtils not using Recycle Bin

Post by Mark1834 » 21 Dec 2021 09:37

When debugging plugins that create temporary files for interim data storage that are subsequently deleted, it would be useful to be able to "undo" the deletion.

I know that os.remove(...) does not use the Recycle Bin, as that is difficult to implement with a cross-platform library. However, fhFileUtils also seems to do an immediate permanent deletion. As this is a Windows-only library, would it be possible to send the file or folder being deleted to the Recycle Bin instead of immediately deleting it? That would bring plugins in line with the core FH application.
Mark Draper

User avatar
tatewise
Megastar
Posts: 27080
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: fhFileUtils not using Recycle Bin

Post by tatewise » 21 Dec 2021 11:53

You say: "That would bring plugins in line with the core FH application."
However, in FH, 'Delete' typically does NOT send files to the Recycle Bin.
In Tools > Plugins if you Delete any Plugin it is gone forever.
In Query > All Custom Queries if you Delete any Query it is gone forever.
I think the deletion of any other custom files is similarly permanent.

I guess you are talking about the fhFileUtils deleteFile() function that uses FSO:DeleteFile().
There are no FSO functions that involve the Recycle Bin.
I tried using moveFile(sPath,sDest) with sDest set to such as "C:\\$Recycle.Bin\\Recycle Bin" without success.

The only method I could find that worked with a script is:

Code: Select all

require("luacom")
local shell = luacom.CreateObject("Shell.Application")
local path = shell:NameSpace(sPath) -- sPath is the parent folder
local file = path:ParseName(sFile) -- sFile is the filename to delete
file:InvokeVerb("delete")
BUT the "delete" always involves a user confirmation dialogue and a Google search offers no solution.

An alternative would be to use moveFile(sPath,sDest) with sDest set to the Temporary folder.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
Mark1834
Megastar
Posts: 2147
Joined: 27 Oct 2017 19:33
Family Historian: V7
Location: South Cheshire, UK

Re: fhFileUtils not using Recycle Bin

Post by Mark1834 » 21 Dec 2021 12:38

Fair enough - it looks more complicated than I thought. Even using 'del' from a command prompt doesn't have an option to use the Recycle Bin, so os.execute() isn't an option either.

It's odd that Microsoft make it so difficult to do in applications, even though File Explorer makes it so easy.

Moving or renaming the file (say by appending the current date/time) while testing is a practical workaround.
Mark Draper

Post Reply