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.
-
1[The same question on SuperUser](https://superuser.com/questions/24662) has most of these answers and more. But just like I warned there, you should be aware that most solutions can fail with files with Unicode/non-Latin characters in their filenames, even with programs that support Unicode, because the command-line itself isn't great for non-Latin characters, sometimes even if you change the code-page. :-\ – Synetech May 08 '20 at 21:28
12 Answers
There is a "recycle.exe" command part of the a collection called cmdutils
"Recycle.exe is a safe replacement for the DEL command, that sends files to the recycle bin instead of deleting them. Recycle is also more flexible than DEL; you can specify multiple files at once (or use wildcards)"
Available at http://www.maddogsw.com/cmdutils
(Tool last updated May 2000)
There is "DeleteXP.exe" is for deleting files from Command Prompt in Windows (Windows 9x and Windows NT 4.0/2000/XP). Unlike, the standard "DEL" command which only deletes the file, Delete XP deletes the files and sends them to the recycle bin. The file(s) to be deleted are passed to it as parameters. It now supports /p and adds two new options /a /d /v.
Just like "del" command in Windows NT/2000/XP, Delete XP supports multiple file names as parameters even in Windows 9x.
Available at http://downloads.easytools.com/Freebies/DeleteXP.zip
(Tool last updated Sep 2004)
There is "recycle.exe" (different developer to one from maddogsw):
C:\>recycle /?
Version 1.11, Copyright (C)2001 Frank P. Westlake
Deletes one or more files by sending them to the Recycle Bin, if possible.
RECYCLE [/PFQ] [/A[[:]attributes]] [[drive:][path]filename
[drive:][path]filename
Specifies the file(s) to delete. Specify multiple files by using wildcards.
/P Prompts for confirmation before deleting each file.
/F Force deleting of read-only files.
/Q Quiet mode, do not ask if ok to delete on global wildcard
/A Selects files to delete based on attributes
attributes R Read-only files
S System files
H Hidden files
A Files ready for archiving
- Prefix meaning not
Available at http://web.archive.org/web/20071026113307/http://gearbox.maem.umr.edu/batch/f_w_util/
http://gearbox.maem.umr.edu/batch/f_w_util/
http://gearbox.maem.umr.edu/batch/f_w_util/recycle.zip
(Tool last updated Jan 2001)
BTW if you want to empty the recylce bin from the command line "cmdutils" has "bin" command:
bin /empty /force
-
The information on the `del` command is incorrect - you can delete multiple files and use wildcards with `del`. – Hashim Aziz Aug 21 '17 at 01:01
-
-
I scanned Recycle.exe at VirusTotal and it was marked as safe ( https://www.virustotal.com/gui/file/01108300bb7f6d30c80f8639ee1c053fb3ff9f97766d80d7ced75e1b0eaa8b5a ) – Gabriel Mar 31 '22 at 14:57
Without external programs - deleteJS.bat
.
It uses Shell.Application
invoke verb method.
usage is simple:
call deleteJS.bat c:\someFile.txt
call deleteJS.bat d:\someFolder

- 55,367
- 18
- 148
- 187
If you have node installed you can add the "trash" module. Works on OS X, Linux and Windows.
$ npm install -g trash
From there when you want to send a file to the recycling bin you just have to type in:
$ trash file.txt

- 391
- 1
- 4
- 13
-
1The install command you suggest didn't work. Instead, this worked: `npm install --global trash-cli` Reference: https://www.npmjs.com/package/trash – narF Jul 25 '17 at 23:18
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') } } }"

- 714
- 7
- 7
-
I think your solution should be accepted in 2022. It can also display a dialog box before deleting a file. – marbel82 Apr 19 '22 at 21:22
recycle.exe -f apple.jpg
from http://www.maddogsw.com/cmdutils/
still works.
March 2014, Windows7 x64, limite UAC Account rights btw. Also tested with some Umlaut Filenames. Files do show up in recycle and with correct restore path.

- 9,625
- 4
- 80
- 110
All answers suggest to use third-party tools but you can use simple move
you just need to determine correct recycle bin path.
In XP it is C:\RECYCLER
, in Vista and later C:\$Recycle.bin
. However that is not everything, it is just a main folder but it contains sub-folders and these are actual bins where you need to move your file.
For example, in my machine that path is:
c:\$Recycle.Bin\S-1-5-21-1291211594-1566655150-3201569215-1000

- 8,826
- 3
- 68
- 92
-
If you do that and view "**Recycle Bin**" in the folder list in Windows explorer it does not show the moved file name in the file name list (tried it on my Win XP system) even though it is in C:\RECYCLER\
folder. "Emptyi Recycle Bin" option does not remove that files done with this method. However, you can open "C:\RECYLER\ – Skip R Jan 23 '15 at 09:12" in windows explorer and "Emptyi Recycle Bin" **DOES** remove that file in that folder. -
7Moving files manually into the Recycle Bin folder is a BAD idea. The Recycle Bin is not just a simple folder, it is a system shell folder that maintains a list of deleted files in an `INFO` file. If you manually put files in it, the bin will not see them and you will not be able to restore them. – Synetech Mar 04 '17 at 02:05
-
But you're able to manually restore them, just like you manually moved them there, right? – Fabian Röling Nov 07 '17 at 15:45
-
@FabianRöling, maybe, maybe not. It depends on what programs have done what with it. Either way, you shouldn't be messing with it manually. – Synetech May 08 '20 at 21:23
-
My previous comment was 2½ years ago, since then I have switched to Linux. And ironically I have implemented a custom trash function there recently, but that one actually correctly renames the file if there are name collision and creates the `.trashinfo` files necessary for restoring. – Fabian Röling May 09 '20 at 05:43
-
Here is a 3rd party program.
Note: I have not tried it.

- 187,200
- 47
- 362
- 445
-
2OK. it looks like there is no build-in command I can use in batch code. – David.Chu.ca Oct 29 '09 at 20:53
A bat script that issues a copy
and del
would be a simple solution...

- 8,039
- 35
- 56
-
1I really wonder, how could you do that with `del` and `copy`, solution is with `move`, see [here](http://stackoverflow.com/a/24806142/1237747) – ST3 Jul 17 '14 at 14:21
-
It may imply setting up your own "recycle" folder and move files to it with a cmd file. It would be fairly easy to append a date stamp to file name being moved. You would need to "empty" this folder manually periodically just like the windows recycle bin. – Skip R Jan 23 '15 at 09:22
-
2I *hope* it implies setting up a fake recycle bin, since files in the actual Recycle Bin are named e.g. C:\$Recycle.Bin\S-1-5-21-983910293-0978783143-9801237884-1001\$RIUIFOK . Randomly copying / moving files into Windows's dir structure seems is unwise. Also, it can't then know Date Deleted or Original Location. Edit: http://stackoverflow.com/questions/1646425/cmd-command-to-delete-files-and-put-them-into-recycle-bin#comment44587300_24806142 points out that files 'introduced' into the Recycle Bin dir structure by moving/copying aren't shown at all in the Recycle Bin in Windows Explorer. – WalterGR Jan 13 '16 at 05:35
-
1Besides, the Recycle Bin isn't just any ordinary directory, it contains a database of its contents. Putting stuff in it manually means you won't be able to view/restore/clear them from the Recycle Bin folder. – Synetech May 08 '20 at 21:21
This depends on where the file is located (and would work for just a file). It first opens the folder, then simulates typing from a keyboard - selecting the file, and then executes the "delete" command, using the del key. To avoid mistakes, the script is set to pause for a number of seconds, before the next command.
set shell = CreateObject("Shell.Application")
shell.Open "C:\Users\server\Desktop"
set wshShell = CreateObject("WScript.Shell")
wscript.Sleep 200
wshShell.SendKeys "testfile"
wshShell.SendKeys "{DEL}"
wscript.Sleep 100
wshShell.SendKeys "%{F4}"
I wrote this code in Notepad and then saved it with a file extension of (.vbs). Then added it to my batch file using
wscript "%~dp0filename.vbs"
Note that the two files (.bat and .vbs) need to be placed in the same folder location, else specify the location (of the .vbs) in the .bat file, if placed in another directory.

- 21
- 4
-
1This isn't a command-prompt/scriptable solution, it's a GUI-automation solution, which isn't really what's being asked for. – Synetech May 08 '20 at 21:24
Here's an autohotkey (AHK) script that could delete files and folders and move them to the recycle bin.
It's also possible to compile it into a console executable. (Just run: "C:\Program Files\AutoHotkey\Compiler\Ahk2Exe.exe" /in trash.ahk /out trash.exe
)
In case you don't have an AHK compiler installed, you can download the exe file from my Github.
Compared to other solutions mentioned in the thread, my app can support
- wildcards
- deletions of files and folders
- a sound playing right after the deletion.
I'm not sure if it's a computer issue, but when I used recycle.exe
, the recycle bin's icon didn't change from empty to something inside.
AHK internally uses SHFileOperation
. I didn't add a check for the existence of a file, which could make the script stronger. Feel free to use it or make some changes.
#NoEnv
#SingleInstance force
#NoTrayIcon
;@Ahk2Exe-ConsoleApp
; must have the directive for console app
; to compile:
; "C:\Program Files\AutoHotkey\Compiler\Ahk2Exe.exe" /in trash.ahk /out trash.exe
; according to https://www.autohotkey.com/docs/v1/lib/FileRecycle.htm
; it uses SHFileOperation
; see also https://stackoverflow.com/a/1646493/2292993
; but recycle.exe from the link above does not cause a chagne in recycle bin icon if a file is deleted
SetBatchLines -1
; https://www.reddit.com/r/AutoHotkey/comments/rf9krl/stdout_to_console/
; https://www.reddit.com/r/AutoHotkey/comments/uw0dr2/how_to_output_to_console/
if %0% = 0
{
; ; alternative solution: `n new line * stdout
; FileAppend Please specify one or more files (supporting wildcard)`n, *
; FileAppend or folder (without trailing backslash) to delete.`n, *
; FileAppend Usage: `n, *
; FileAppend recycle.exe "C:\temp files\*.tmp" "folder" ...`n, *
out := 0
stdout := FileOpen("*", "w", "UTF-8")
stdout.Write("Please indicate which file(s) or folder(s) you would like to delete`n")
stdout.Write("Use wildcards if necessary.`n")
stdout.Write("Do not include a backslash at the end of the folder name.`n")
stdout.Write("`n")
stdout.Write("Usage: `n")
; Double up the quotes to escape them.
stdout.Write(" trash.exe ""C:\temp files\*.tmp"" ""folder"" ...`n")
stdout.Close()
ExitApp % out
}
; https://www.autohotkey.com/docs/v1/lib/FileRecycle.htm
Loop %0%
{
file := %A_Index%
FileRecycle, %file%
}
SoundPlay *64
ExitApp

- 1,541
- 1
- 19
- 17
I don't think these 3rd party tools existed when this question was first asked, but they may work better on modern OSes:

- 490
- 1
- 5
- 13
You can try RecycleIt. It will send files to the Windows Recycle Bin via command line.
--Mike

- 109
- 1
- 3