Date: 02-16-2022
Return to Index
created by gbSnippets
'The PowerBASIC KILL command does NOT send the deleted file
'to the Windows recycle bin. Here's how to do it.
'Primary Code
'Credit: Fred Buffington, Trento Castricone, Michael Mattias
http://www.powerbasic.com/support/pbforums/showthread.php?p=321576
Function RecycleBinSilent(ByVal FileName AS String) As Long
Local shfo AS SHFILEOPSTRUCT
Local szSource As AsciiZ * %MAX_PATH
Local lResult As Long
Reset szSource
szSource = FileName 'NOTE: must be full path name
Reset SHFO
SHFO.hWnd = GetDesktopWindow()
shfo.wFunc = %FO_DELETE
shfo.pFrom = VarPTR(szSource)
shfo.fFlags = %FOF_ALLOWUNDO Or %FOF_SIMPLEPROGRESS Or %FOF_WANTNUKEWARNING
' shfo.fFlags = %FOF_ALLOWUNDO Or %FOF_NOCONFIRMATION Or %FOF_WANTNUKEWARNING
lResult = SHFileOperation(shfo)
Function = shfo.fAnyOperationsAborted
End Function
'Note the optional flag line - one gives progress, the other does not
'Compilable Example: (Jose Includes)
'In this example, an existing file "myfile.txt" is sent to the recycle bin.
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
Local fName$
fName$ = Exe.path$ + "myfile.txt"
If IsFile(fName$) Then RecycleBinSilent (fName$)
End If
End Function
Function RecycleBinSilent(ByVal FileName AS String) As Long
Local shfo AS SHFILEOPSTRUCT
Local szSource As AsciiZ * %MAX_PATH
Local lResult As Long
Reset szSource
szSource = FileName
Reset SHFO
SHFO.hWnd = GetDesktopWindow()
shfo.wFunc = %FO_DELETE
shfo.pFrom = VarPTR(szSource)
' shfo.fFlags = %FOF_ALLOWUNDO Or %FOF_NOCONFIRMATION Or %FOF_ALLOWUNDO
shfo.fFlags = %FOF_ALLOWUNDO Or %FOF_SIMPLEPROGRESS Or %FOF_ALLOWUNDO
lResult = SHFileOperation(shfo)
Function = shfo.fAnyOperationsAborted
End Function
'gbs_00310
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm