How can I move files to the Recycle Bin in a Windows batch script or Perl?
use Win32::FileOp qw(Recycle);
Recycle(@ARGV);
Write a VBS script (Original Link) then call it with MyDelScript.vbs
function main()
{
if (WScript.Arguments.length != 1)
{
WScript.Echo("<Insert informative error message here>");
return;
}
var Path = WScript.Arguments(0);
var Shell = WScript.CreateObject("Shell.Application");
var Item = Shell.Namespace(0).ParseName(Path);
Item.InvokeVerb("delete");
}
The Win32::FileOp module has a Recycle
function. From the docs:
Recycle @filenames
Send the files into the recycle bin. You will not get any confirmation dialogs. Returns true if successful.