WindowsXP x86, PB 5.20 Beta8. Compiled as Unicode.
Code: Select all
Global NewList sgToTrash.s()
AddElement(sgToTrash())
sgToTrash() = "C:\MyTemp\Folder02\Text Document_202.txt"
Global NewList sgFilesToTrash.s()
AddElement(sgFilesToTrash())
sgFilesToTrash() = "C:\MyTemp\Folder02\Text Document_202.txt"
AddElement(sgFilesToTrash())
sgFilesToTrash() = "C:\MyTemp\Folder02\Text Document_204.txt"
Procedure ToRecycleBin(sFile.s)
;------------------------------
Protected SHFileOp.SHFILEOPSTRUCT
SHFileOp\pFrom = @sFile
SHFileOp\wFunc = #FO_DELETE
SHFileOp\fFlags = #FOF_ALLOWUNDO | #FOF_NOCONFIRMATION ;| #FOF_SILENT
If SHFileOperation_(@SHFileOp) = 0
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
;==== Fails using SelectElement ===================================================================
FirstElement(sgFilesToTrash())
SelectElement(sgFilesToTrash(),1)
Debug "sgFilesToTrash()-->" + sgFilesToTrash() + "<--" ;C:\MyTemp\Folder02\Text Document_204.txt
ToRecycleBin(sgFilesToTrash())
;Error returned: Cannot delete file: Cannot read from the source file or disk.
;==========================================================================================
;==== Fails using FirstElement ====================================================================
FirstElement(sgFilesToTrash())
Debug "sgFilesToTrash()-->" + sgFilesToTrash() + "<--" ;C:\MyTemp\Folder02\Text Document_202.txt
ToRecycleBin(sgFilesToTrash())
;Error returned: Cannot delete file: Cannot read from the source file or disk.
;==========================================================================================
;==== Works if only one Element exists =============================================================
Debug "sgToTrash()-->" + sgToTrash() + "<--" ;C:\MyTemp\Folder02\Text Document_202.txt
ToRecycleBin(sgToTrash())
;==========================================================================================
;==== Works Explicitly ==========================================================================
ToRecycleBin("C:\MyTemp\Folder02\Text Document_204.txt")
;==========================================================================================
Edit: See solution in my post below

