开发者

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

Is 开发者_Go百科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.


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


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


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


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') } } }"


Here is a 3rd party program.

http://www.watchingthenet.com/send-deleted-files-to-the-recycle-bin-when-using-windows-command-prompt.html

Note: I have not tried it.


A bat script that issues a copy and del would be a simple solution...


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.


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

--Mike

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜