#1 2016-03-22 16:48

Andrew
Senior Member
Registered: 2008-05-22
Posts: 542

Delete files to Recycle Bin

Hi Denis,

Would it be possible for safety purposes to modify WideDeleteFile() so that it can optionally delete to the Recycle Bin? In short, change this:

function WideDeleteFile(const FileName: WideString): Boolean;

to something like this:

function WideDeleteFile(const FileName: WideString; UseRecycleBin: Boolean): Boolean;

I'm assuming if this is done then standard Windows APIs will be used, so the OS itself will take care of things like checking if the Recycle Bin is available or not, whether it is large enough to contain the deleted file and so on.

Offline

#2 2016-03-23 00:55

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,479

Re: Delete files to Recycle Bin

Absolutely. This should get added in v6.4.0.1 Beta.

The function will probably be called WideDeleteFileToRecycleBin, to keep the signature of existing functions unchanged for backwards compatibility.

Offline

#3 2016-03-23 17:24

Andrew
Senior Member
Registered: 2008-05-22
Posts: 542

Re: Delete files to Recycle Bin

den4b wrote:

Absolutely. This should get added in v6.4.0.1 Beta.

Thanks!

den4b wrote:

The function will probably be called WideDeleteFileToRecycleBin, to keep the signature of existing functions unchanged for backwards compatibility.

Doesn't PS have the concept of default arguments, or function overloading? That way both single and multiple arguments would work with the same function name and no existing code would break. In fact, it would probably help to consolidate other functions having multiple versions too, and would lead to an overall cleaner API.

Also, is the lack of a complementary WideDeleteDir() function deliberate, or just something that hasn't been implemented yet? Wonder if it makes sense, especially considering that things like recursive deletion, non-empty dirs etc. will need to be dealt with. Perhaps best not to add it from a safety perspective, or perhaps only WideDeleteEmptyDir() can be added?

Last edited by Andrew (2016-03-23 17:38)

Offline

#4 2016-03-23 23:03

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,479

Re: Delete files to Recycle Bin

Andrew wrote:

Doesn't PS have the concept of default arguments, or function overloading?

PascalScript engine doesn't support parameter defaults and function overloading.

Andrew wrote:

Is the lack of a complementary WideDeleteDir() function deliberate, or just something that hasn't been implemented yet?

Nobody has asked for it, until now.

It will be added as WideRemoveDir and will remove a directory only if it is empty, just like in FPC and Delphi.

Offline

#5 2016-03-24 14:44

Andrew
Senior Member
Registered: 2008-05-22
Posts: 542

Re: Delete files to Recycle Bin

den4b wrote:

PascalScript engine doesn't support parameter defaults and function overloading.

Too bad. Oh well, can't be helped I suppose.

den4b wrote:
Andrew wrote:

Is the lack of a complementary WideDeleteDir() function deliberate, or just something that hasn't been implemented yet?

Nobody has asked for it, until now.

It will be added as WideRemoveDir and will remove a directory only if it is empty, just like in FPC and Delphi.

That'll do nicely. Waiting for 6.4.0.1 now. smile

Offline

Board footer

Powered by FluxBB