November 28, 2020, 01:52:24 PM

Author Topic: [bb] Delete files to Recycle Bin by Kev [ 1+ years ago ]  (Read 485 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Delete files to Recycle Bin by Kev [ 1+ years ago ]
« on: June 29, 2017, 12:28:39 AM »
Title : Delete files to Recycle Bin
Author : Kev
Posted : 1+ years ago

Description : When we delete files in blitz3d these are gone for good, use the code below to move them to the recycle bin in case you want a user to recover them later

Code :
Code: BlitzBasic
  1. decls needs to be added to userlibs.
  2.  
  3. .lib "shell32.dll"
  4. shell32_SHFileOperation%(lpFileOp*):"SHFileOperationA"
  5.  
  6. .lib "user32.dll"
  7. user32_CallWindowProc%(lpPrevWndFunc*,hwnd%,msg%,wParam%,lParam$):"CallWindowProcA"
  8.  
  9. ;----------------------------------------------------------------------------------------
  10.  
  11. ; and a simple example
  12.  
  13. Const FO_DELETE = $3
  14. Const FOF_ALLOWUNDO = $40
  15. Const FOF_NOCONFIRMATION = $10
  16. Const FOF_SILENT = $4
  17.  
  18. ; send example file to bin
  19. If send_to_bin("e:      mp.txt") = 0 Then
  20.         Print "sent to bin"
  21. Else
  22.         Print "problem sending file to bin"
  23. EndIf
  24.  
  25. MouseWait
  26. End
  27.  
  28. Function send_to_bin(filename$)
  29.  
  30.         ; build quick asm call to obtain string address
  31.         asm = CreateBank(5)
  32.         Restore asm_data
  33.         For add_byte = 0 To 4
  34.                 Read byte
  35.                 PokeByte asm,add_byte,byte
  36.         Next
  37.         str_addr = user32_CallWindowProc(asm,0,0,0,filename$)
  38.  
  39.         ; build struct
  40.         bank = CreateBank(24)
  41.         PokeInt bank,4,FO_DELETE
  42.         PokeInt bank,8,str_addr
  43.         PokeInt bank,16,FOF_ALLOWUNDO Or FOF_NOCONFIRMATION Or FOF_SILENT
  44.  
  45.         ; delete file to bin
  46.         value =  shell32_SHFileOperation(bank)
  47.        
  48.         FreeBank bank
  49.         FreeBank asm
  50.        
  51.         Return value
  52.  
  53. End Function
  54.  
  55. .asm_data
  56. Data $8b,$44,$24,$10,$c3


Comments :


markcw(Posted 1+ years ago)

 Cool, I didn't know you could do that. Nice one Kev.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal