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.
-
The same question on SuperUser 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. :-\– SynetechMay 8 '20 at 21:28
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
delcommand is incorrect - you can delete multiple files and use wildcards withdel. Aug 21 '17 at 1:01 -
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
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.
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
-
The install command you suggest didn't work. Instead, this worked:
npm install --global trash-cliReference: npmjs.com/package/trash– narFJul 25 '17 at 23:18
Here is a 3rd party program.
Note: I have not tried it.
-
2OK. it looks like there is no build-in command I can use in batch code. Oct 29 '09 at 20:53
A bat script that issues a copy and del would be a simple solution...
-
1
-
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 RJan 23 '15 at 9: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: stackoverflow.com/questions/1646425/… 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.– WalterGRJan 13 '16 at 5: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.– SynetechMay 8 '20 at 21:21
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
-
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\<sid> folder. "Emptyi Recycle Bin" option does not remove that files done with this method. However, you can open "C:\RECYLER\<sid>" in windows explorer and "Emptyi Recycle Bin" DOES remove that file in that folder.– Skip RJan 23 '15 at 9:12
-
5Moving 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
INFOfile. If you manually put files in it, the bin will not see them and you will not be able to restore them.– SynetechMar 4 '17 at 2:05 -
But you're able to manually restore them, just like you manually moved them there, right? Nov 7 '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.– SynetechMay 8 '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
.trashinfofiles necessary for restoring. May 9 '20 at 5:43
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') } } }"
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.
-
1This isn't a command-prompt/scriptable solution, it's a GUI-automation solution, which isn't really what's being asked for.– SynetechMay 8 '20 at 21:24
You can try RecycleIt. It will send files to the Windows Recycle Bin via command line.
--Mike