Delete files to Recycle Bin?

Blitz3D Forums/Blitz3D Programming/Delete files to Recycle Bin?

Danny(Posted 2008) [#1]
Does anyone know how to delete files from Blitz to the windows recycle bin, so they could possibly be restored later ?

Couldn't find anything in environment variables, code archives or other obvious ways to do it...?!

Thanks,
Danny


Gabriel(Posted 2008) [#2]
DeleteFile ?


Danny(Posted 2008) [#3]
Err.. Nope. That will simply Delete the file which will be lost forever. I want to send it to the desktop's recycle bin instead.. ?!


Ross C(Posted 2008) [#4]
Couldn't you just move the file? I'm sure the recycle bin has a folder somewhere in c:


Kryzon(Posted 2008) [#5]
http://support.microsoft.com/kb/136517 - this has some information on the Recycle Bin's folder\file structure.

Good luck.


Beaker(Posted 2008) [#6]
This might help a little:
http://www.purebasic.fr/english/viewtopic.php?t=3783


Gabriel(Posted 2008) [#7]
Err.. Nope. That will simply Delete the file which will be lost forever.
Huh. So they do. I'm sure they used to go to the recycle bin. I wonder if something changed with Blitz or if depends on the operating system.


Knight #51(Posted 2008) [#8]
You could simply create a function that moves a file to the Recycle Bin and removes it from the game, or you could try something like:





That will give the effect of deletion without actually deleting it from you computer. I didn't try it yet so let me know how it turns out.


Danny(Posted 2008) [#9]
Thanks All for the feedback.

yes Gizmo, that's the idea I'm hoping for: simply "moving" (renaming) the file to the recycle folder. Point is HOW do I obtain that Recycle folder's Full Path including Drive letter? That's pretty much the mystery I'm trying to solve.. I'm not expecting it's the same folder/drive for every system/windows version - and sjeesh knows what Vista will do in this context!

Beaker seems to have found what I need with that 'AllowUndo' flag before deleting a file - although I wouldn't have a clue how to translate that to B3D... :(

D.


xlsior(Posted 2008) [#10]
Point is HOW do I obtain that Recycle folder's Full Path including Drive letter


The recyclebin actually exists on ALL drives -- if you delete something from C:\ it ends up in the recyclebin folder on your C: drive, if you delete it from Z: it ends up in the recycle bin folder on your Z: drive.

The reason: Moving a file from one folder is just a matter of updating the file allocation table to point the filehandle to the new folder which is near-instantanious, while moving it to a different drive would entail making a full copy of the file which can take a LONG time for large files.

I'm sure there is a windows API or registry setting that will give you the directory name for the recycle bin. (which is important, since IIRc there are slight variations in the folder name across different windows versions, not to mention that it is likely called differently in all the non-English windows versions)

Last but not least: You can also *disable* the recycle bin on some (or all) drives, so don't just assume that it's always there.


Ross C(Posted 2008) [#11]
We not make your own recycle bin, on the directory of your program? Your program can restore the files if needed, or you can give the location of the folder, so users may copy it back themselves.


Kev(Posted 2008) [#12]
Hi Danny long time no see, Use the API ShFileOperation() found in shell32.dll to send the file to recycle bin.

kev


Kev(Posted 2008) [#13]
For those that want this feature.

decls
.lib "shell32.dll"
shell32_SHFileOperation%(lpFileOp*):"SHFileOperationA" 

.lib "user32.dll"
user32_CallWindowProc%(lpPrevWndFunc*,hwnd%,msg%,wParam%,lParam$):"CallWindowProcA"


example


Const FO_DELETE = $3
Const FOF_ALLOWUNDO = $40
Const FOF_NOCONFIRMATION = $10
Const FOF_SILENT = $4

; send example file to bin
If send_to_bin("e:\tmp.txt") = 0 Then
	Print "sent to bin"
Else
	Print "problem sending file to bin"
EndIf

MouseWait
End

Function send_to_bin(filename$)

	; build quick asm call to obtain string address
	asm = CreateBank(5)
	Restore asm_data
	For add_byte = 0 To 4
		Read byte
		PokeByte asm,add_byte,byte
	Next
	str_addr = user32_CallWindowProc(asm,0,0,0,filename$)

	; build struct
	bank = CreateBank(24)
	PokeInt bank,4,FO_DELETE 
	PokeInt bank,8,str_addr
	PokeInt bank,16,FOF_ALLOWUNDO Or FOF_NOCONFIRMATION Or FOF_SILENT

	; delete file to bin
	value =  shell32_SHFileOperation(bank)
	
	FreeBank bank
	FreeBank asm
	
	Return value

End Function

.asm_data
Data $8b,$44,$24,$10,$c3




Danny(Posted 2008) [#14]
@ Ross C: Very good idea indeed - and probably safest :) I considered this but the amounts of data being purged (100's megs/multiple gigs at one time) is too much for comfort to store in a folder people might very easily forget about - and crash their system..

@xlsior: Very good points you're raising about considering language - or absence of the recycle bin! Thanks for that - I didn't think about that before!

@ Kev. You still my main man! The son I never had! :))
Thanks for that again. I will test it out (I'm sure it'll work) but curious to see how it reacts when there is no recycle bin (probably just deletes it). BTW, talk soon again, I need some special protection only you can provide ;)

Thanks again all, you really saved my skin on this one!

Danny,--


Kev(Posted 2008) [#15]
cool danny no problem, i would think it would throw an soft error if the recycle bin is removed. im sure the api can handle this :) umm you need some special protection boot's is the place to go mate :P

kev