Trashing a file in Windows

Ken Ray kray at sonsothunder.com
Fri Jan 4 16:43:41 EST 2008


On Thu, 3 Jan 2008 20:57:27 -0800 (PST), fioravantig wrote:

> Does anyone have a good method for moving files/folders to the Recycle Bin
> in Windows?

As opposed to truly deleting the file with "delete file..." right? Well 
AFAIK the only way to do that is by executing VBScript on Windows... 
here's the VBS code that worked for me (with caveats mentioned below):

Const RECYCLE_BIN = &Ha&
Const FILE_TO_MOVE = "C:\Temp\MyFile.txt"
Set objShell = CreateObject("Shell.Application")
Set recycleFolder = objShell.NameSpace(RECYCLE_BIN)
recycleFolder.MoveHere FILE_TO_MOVE
WScript.Echo Err.Number

However although this works by putting it in a file and 2x-clicking it 
(you get "0" in the dialog box), if I try to write the code out to a 
file (let's say, "C:\Test.vbs") and execute it with:

  get shell("cscript.exe //nologo c:\Test.vbs")

I get no error (0 is returned), but the file is not moved to the 
Recycle Bin. I tried it in Rev 2.9 (which has built-in VBS support), 
and it *worked*, but the result was "execution error". And oddly, if I 
remove the "WScript.Echo" line from the script, and double-click the 
.vbs file, I get the same "no error, but doesn't move the file" problem.

This may have to do with security restrictions in Windows, but I've 
executed dozens of VBScripts by code in the past and this is the first 
one to behave this way. 

Any ideas, anyone? Or can anyone else test this and see if you get the 
same result?

Thanks,

Ken Ray
Sons of Thunder Software, Inc.
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/



More information about the use-livecode mailing list