I just noticed that the old method (shFileOperation) to send files to the recycle bin no longer seems to work.
I was able to get iFileOperation to delete a file, but not recycle it.
Has anyone else already solved this?
sending a file to the recycle bin?
Re: sending a file to the recycle bin?
Hi
Edit :Modified
Code: Select all
File$ = "e:\mmedia\pictures\3.jpg"
memory = AllocateMemory( (Len(File$)+2 ) * SizeOf(Character))
SHFileOp.SHFILEOPSTRUCT
If memory
PokeS(memory,File$)
SHFileOp\pFrom = memory
SHFileOp\wFunc = #FO_DELETE
SHFileOp\fFlags = #FOF_ALLOWUNDO|#FOF_SILENT
result = SHFileOperation_(SHFileOp)
FreeMemory(memory)
EndIf
Last edited by RASHAD on Mon Nov 19, 2018 5:56 am, edited 1 time in total.
Egypt my love
Re: sending a file to the recycle bin?
Hi Rashad. Yes, that's basically what I used:
I had a version of that; but it was failing on win10... I'll try yours & try to figure out why mine was failing...
Thanks.
-j
I had a version of that; but it was failing on win10... I'll try yours & try to figure out why mine was failing...
Thanks.
-j
Re: sending a file to the recycle bin?
Yes this seems still work.
I modified my such example, previously I was using raw arrays of strings or string pointers, but that also didn't works anymore so your variant with memory packing remains.
This is one for multiple files.
I also tried to use IFileOperation interface for this, but too problematic use that from PB.
Code: Select all
; Deletes specified files using Windows Shell
; Files$ a list of files/folders separated using "|"
; RETURN: #True on success, #False else
Procedure SHDeleteFiles(Files$)
Protected SrcCount = CountString(Files$, "|")
Protected *fMem = AllocateMemory(StringByteLength(Files$) + SizeOf(Character) * (SrcCount+2))
Protected *cMem = *fMem
Protected fOp.SHFILEOPSTRUCT
Protected Res
Protected TFile$
If *fMem
While SrcCount >= 0
TFile$ = StringField(Files$, SrcCount+1, "|")
If TFile$
*cMem = *cMem + PokeS(*cMem, TFile$, -1, #PB_String_NoZero) + SizeOf(Character)
EndIf
SrcCount - 1
Wend
With fOp
\pFrom = *fMem
\wFunc = #FO_DELETE
\fFlags = #FOF_ALLOWUNDO ; + other flags
EndWith
Res = SHFileOperation_(fOp)
FreeMemory(*fMem)
EndIf
ProcedureReturn Bool(Res = 0)
EndProcedure
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
Re: sending a file to the recycle bin?
Works nicely. Now here is a modified version which enhances the DeleteFile-function from PureBasic with a #PB_FileSystem_Recycle-flag to recycle the file(s) instead of deleting them (obviously still only for Windows):
Code: Select all
#PB_FileSystem_Recycle = 4096
Procedure DeleteFile_Ext(FileName$,Flags)
If Flags&#PB_FileSystem_Recycle
Protected *fMem = AllocateMemory(StringByteLength(FileName$)+2*SizeOf(Character)),fOp.SHFILEOPSTRUCT,Res
PokeS(*fMem,FileName$)
With fOp
\pFrom=*fMem
\wFunc=#FO_DELETE
\fFlags=#FOF_ALLOWUNDO|#FOF_SILENT
EndWith
Res=SHFileOperation_(fOp)
FreeMemory(*fMem)
ProcedureReturn Bool(Res=0)
Else
ProcedureReturn DeleteFile(FileName$,Flags)
EndIf
EndProcedure
Macro DeleteFile(iFile,iFlags)
DeleteFile_Ext(iFile,iFlags)
EndMacro
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB