CMD Command to delete files and put them into Recycle Bin?

Viewed 36336

Is there any console command "del" to delete files from a folder and put them into Recycle Bin? del command will delete files and not in Recycle Bin.

10 Answers

Ok, this is an extremely old thread, but this solution has a few properties that are not addressed in the other answers:

  • It uses PowerShell with two Microsoft.VisualBasic COM object's static methods to allow deletion of folders and files without a confirmation (so it can be used without 3rd party utilities, and runs unattended)
  • It allows passing wildcards so it's not so slow when deleting multiple files

Paste this one-liner in a file named recycle.bat (so you can easily call it from the command line):

@powershell.exe -nologo -noprofile -Command "& {Add-Type -AssemblyName 'Microsoft.VisualBasic'; Get-ChildItem -Path '%~1' | ForEach-Object { if ($_ -is [System.IO.DirectoryInfo]) { [Microsoft.VisualBasic.FileIO.FileSystem]::DeleteDirectory($_.FullName,'OnlyErrorDialogs','SendToRecycleBin') } else { [Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile($_.FullName,'OnlyErrorDialogs','SendToRecycleBin') } } }"

You can try RecycleIt. It will send files to the Windows Recycle Bin via command line.

--Mike

Related