[bmx] RecycleBinPath() by Ked [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:38

Previous topic - Next topic

BlitzBot

Title : RecycleBinPath()
Author : Ked
Posted : 1+ years ago

Description : Returns the physical path of the Recycle Bin (Windows XP and earlier)

Code :
Code (blitzmax) Select
Function RecycleBinPath:String()
Local drive:String=GetEnv_("SYSTEMDRIVE")
Local os:String=GetEnv_("OS")

If Lower(os)="windows_nt"
drive:+"RECYCLER"
Else
drive:+"RECYCLED"
EndIf

Local dir:String[]=LoadDir(drive)
Local path:String=Null
If dir
path=drive+dir[0]
EndIf

Return path
EndFunction


Comments :


xlsior(Posted 1+ years ago)

 ...Except on non-English versions of windows, where the folder won't be named 'recycled', but whatever the local translation happens to be.This is one of those things where you ought to use the windows API (or at a bare minimum read it from the registry) rather than making assumptions...


N(Posted 1+ years ago)

 Also, why make it Windows-only?


Ked(Posted 1+ years ago)

 <div class="quote"> ...Except on non-English versions of windows, where the folder won't be named 'recycled', but whatever the local translation happens to be. </div>Right. English only. :)<div class="quote"> This is one of those things where you ought to use the windows API (or at a bare minimum read it from the registry) rather than making assumptions... </div>I don't think this was an assumption. I just grabbed information from MSDN.<div class="quote"> Also, why make it Windows-only? </div>I only have a Windows computer. And this was just for something I am working on.


xlsior(Posted 1+ years ago)

 Interesting,s ince Microsoft's own design guidelines would have you use their appropriate API's to obtain the correct info reliably... Using the environment variables is one thing when you're trying to determine the system drive, but there is no such thing to help you pick the actual *folder* that the recycle bin is stored at.Even if you add additional checks to make sure that it is indeed an English-language install, you still don't account for other variances like people tweaks to repoint their recyclebin to a custom location. Hey, it happens. :-?It also wouldn't be future-proof: for all we know, Windows 8 may give it a different name again altogether.Using the API's would always give you the correct location, regardless of the language or how 'creative' someone has been with their OS settings.


Ked(Posted 1+ years ago)

 Good to know, but this was just for something I was working on.


_PJ_(Posted 1+ years ago)

 <div class="quote"> there is no such thing to help you pick the actual *folder* that the recycle bin is stored at. </div>The "RECYCLER" name itself should be under one of the MUI lists in the registry, so regardless of the language, it can be found.As far as I know, (Speaking Windows - I had no idea other OS even have recycle bin folders :D ) it's not possible to relocate the Recycle Bin(s), except by disabling it on one drive annd enabling it on another.Even so, it's not much help because the actual recycle bin 'contents' might not be in "RECYCLER" directly, but in a folder within that with a generated name referring to the current User by session. I'm unsure if  this is affected by FUS or similar, I only have the default users and my own account on this machine.You could use NextFile presumably and identify the folder which would be easier than checking the HKEY_USERS registry entry for the name.


_PJ_(Posted 1+ years ago)

 Actually, scratch that....after I've read this:<a href="../Community/posts0ab0.html?topic=80751#910343" target="_blank">http://www.blitzbasic.com/Community/posts.php?topic=80751#910343</a>and considering HOW the recycle bin works (by 'flagging' files, rather than moving them anywhere - (Yes, even if you do the trick mentioned and delete a file on drive X then open up the Recycleron C it will be there, however, the FILE DATA is still on drive X. That doesn't change unless you disable the Recycle Bin entirely for X.Anyway, it seems that the actual 'folders' for recycled files are not at all real folders. Not even masked names like for the "CD Burning" or "My Documents" type folders, nope. I think they are just a 'window' meh bad word, bt anyway, a window that shows the information retrieved by Windows OS when it looks for the files flagged as "In the recycle Bin", so I'm guessing you can never truly obtain a PATH to the Recycle Bin contents, the closest you could get, is to mimic Windows by finding all the files flagged and then maybe copy them to a single location, or store their individual paths (which I would imagine remain the same as before they were 'deleted'.)I'm doubtful, though to how possible it would be to work with these files, seeing as how normally a 'deleted' (i.e. in the recycle bin file) is no longer accessible by its original path from blitz.