Delete a file to the Windows 10 recycle bin [SOLVED]
Delete a file to the Windows 10 recycle bin [SOLVED]
I have found numerous "Delete to recycle bin" examples in this forum and other sources, but I am unable to make them work.
Does anyone have a procedure that works in PB 5.73 under Windows 10.
TIA
Dave
Does anyone have a procedure that works in PB 5.73 under Windows 10.
TIA
Dave
Last edited by davebar on Sat Mar 20, 2021 6:12 pm, edited 1 time in total.
Re: Delete a file to the Windows 10 recycle bin
Post your code so we can see what's wrong. The other examples work for me.
Re: Delete a file to the Windows 10 recycle bin
The reason for my question is that I do NOT have any code to post.
Here is one of several examples I found:
http://forums.purebasic.com/english/vie ... 13&t=22500
Like most other examples it is quite old and I suspect is not valid for Win 10.
Here is one of several examples I found:
http://forums.purebasic.com/english/vie ... 13&t=22500
Like most other examples it is quite old and I suspect is not valid for Win 10.
Re: Delete a file to the Windows 10 recycle bin
Can you please point me to one of the other examples that work for you.BarryG wrote:The other examples work for me.
Re: Delete a file to the Windows 10 recycle bin
This one, from the link you posted -> viewtopic.php?p=306504#p306504davebar wrote:Can you please point me to one of the other examples that work for you.
To remove the confirmation prompt, I changed one line to this:
Code: Select all
SHFileOp\fFlags=#FOF_ALLOWUNDO|#FOF_NOCONFIRMATION
Re: Delete a file to the Windows 10 recycle bin
Thanks. Here's my code that does not work:
MyFile$ is not deleted and the recycle bin is empty when the execution finishes.
Code: Select all
Procedure.l RECYCLEFile(File$); - Delete a file and move it in the RECYCLE-Bin
SHFileOp.SHFILEOPSTRUCT
SHFileOp\pFrom=@File$
SHFileOp\wFunc=#FO_DELETE
SHFileOp\fFlags=#FOF_ALLOWUNDO | #FOF_NOCONFIRMATION
ProcedureReturn SHFileOperation_(SHFileOp)
EndProcedure
MyFile$ = "D:\Temp\Test.txt"
Debug RECYCLEFile(MyFile$) ; Returns 2
Re: Delete a file to the Windows 10 recycle bin
Code: Select all
Procedure _Recycle(File$)
SHFileOp.SHFILEOPSTRUCT
m = AllocateMemory(( Len(File$)+2 ) * SizeOf(Character) )
If m
PokeS(m,File$)
SHFileOp\pFrom = m
SHFileOp\wFunc = #FO_DELETE
SHFileOp\fFlags = #FOF_ALLOWUNDO|#FOF_SILENT
result = SHFileOperation_(SHFileOp)
FreeMemory(m)
EndIf
EndProcedure
Procedure _Delete(File$)
SHFileOp.SHFILEOPSTRUCT
m = AllocateMemory(( Len(File$)+2 ) * SizeOf(Character) )
If m
PokeS(m,File$)
SHFileOp\pFrom = m
SHFileOp\wFunc = #FO_DELETE
SHFileOp\fFlags = #FOF_SILENT|#FOF_NOCONFIRMATION
result = SHFileOperation_(SHFileOp)
FreeMemory(m)
EndIf
EndProcedure
Egypt my love
Re: Delete a file to the Windows 10 recycle bin
Thanks Rashad! Works perfectly
Re: Delete a file to the Windows 10 recycle bin
Hmm, I used your code and same file location and the procedure returned 0 (success) for me and recycled the file. Let us know what Rashad's code does.davebar wrote:MyFile$ is not deleted and the recycle bin is empty when the execution finishes.
[Edit] Oops, I see you replied while I was replying. Cool! I'll switch to Rashad's code too, then, to ensure 100% compatibility with all my users computers.
Re: Delete a file to the Windows 10 recycle bin
Thanks anyway BarryG, for taking the time to try and help.
Kind Regards
Dave
Kind Regards
Dave