Code archives/File Utilities/RecycleBinPath()

This code has been declared by its author to be Public Domain code.

Download source code

RecycleBinPath() by Ked2009
Returns the physical path of the Recycle Bin (Windows XP and earlier)
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

xlsior2009
...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...


N2009
Also, why make it Windows-only?


Ked2009
...Except on non-English versions of windows, where the folder won't be named 'recycled', but whatever the local translation happens to be.

Right. English only. :)

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...

I don't think this was an assumption. I just grabbed information from MSDN.

Also, why make it Windows-only?

I only have a Windows computer. And this was just for something I am working on.


xlsior2009
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.


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


_PJ_2009
there is no such thing to help you pick the actual *folder* that the recycle bin is stored at.



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_2009
Actually, scratch that....

after I've read this:

http://www.blitzbasic.com/Community/posts.php?topic=80751#910343

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.


Code Archives Forum