1

Behold the following script that I have managed to create at the moment (it's a batch script, and this is the whole thing):

echo Recycle %%A
recycle "D:\7) Temporary\Media Caches\Pr\*.*"

What this will do, in my above example, is recycle the contents of the specified folder. It uses the following plugin to do so, which should be able to work the same way as the regular del command: http://www.maddogsw.com/cmdutils/

However, when I use this, it does not ask for confirmation and instead immediately recycles the contents of the folder. Similarly, it recycles EVERYTHING within the folder. My two goals are the following:

I need to be able to exclude specific files that are within this folder from being recycled (specifically, the hidden "desktop" file that I need to keep for personal reasons).

And it needs to ask for confirmation each time that I double-click the script. I've tried several things here (such as /P) but I'm either not putting it in the right place or it might not work with this recycle plugin. For those of you trying to help me, treat it as if it was del and then see if you can accomplish my two aforementioned goals. I'm not sure how to exclude a specific file (or perhaps multiple files) nor am I sure how to get it to ask for confirmation. While a dialogue box would be much nicer than having the command prompt come up (which, I don't know how to create a dialogue box) function is the most important, and if it has to be done with the command prompt, that's okay. So remember, my goals:

  1. Ask for confirmation before recycling the contents of the folder (not the folder itself).
  2. Exclude the hidden "desktop" system file within the folder from being sent to the recycle bin.
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • If those are the only two lines in the entire script, you don't need the `echo Recycle %%A` line since it doesn't do anything. – SomethingDark Feb 15 '15 at 05:33
  • check also this - https://raw.githubusercontent.com/npocmaka/batch.scripts/master/hybrids/jscript/deleteJS.bat - will allow you to recycle item without external software – npocmaka Apr 26 '15 at 07:39

1 Answers1

0

This batch recycles all files in the specified folder except hidden files.

@echo off
set "Answer=N"
set /P "Answer=Recycle folder (Y/N): "
if /I "%Answer%"=="Y" (
    for %%F in ("D:\7) Temporary\Media Caches\Pr\*.*") do recycle.exe -f "%%~F"
)
set "Answer="

Best would be to specify recycle.exe with full path in the batch file.

The file desktop.ini is ignored automatically if it has system and hidden attribute set as by default because hidden files are by default ignored by command FOR.

A variation of above to recycle also all subdirectories additionally to all files with the exception of files and subdirectories with hidden attribute set.

@echo off
set "Folder=D:\7) Temporary\Media Caches\Pr"
set "Answer=N"
set /P "Answer=Recycle folder (Y/N): "
if /I "%Answer%"=="Y" (
    for /F "delims=" %%F in ('dir /A-H /B "%Folder%"') do recycle.exe -f "%Folder%\%%~nxF"
)
set "Answer="
set "Folder="

And one more version recycling also hidden subfolders and files, but not the file with name desktop.ini independent on its file attributes.

@echo off
set "Folder=D:\7) Temporary\Media Caches\Pr"
set "Answer=N"
set /P "Answer=Recycle folder (Y/N): "
if /I "%Answer%"=="Y" (
    for /F "delims=" %%F in ('dir /A /B "%Folder%"') do (
        if /I "%%~nxF" NEQ "desktop.ini" recycle.exe -f "%Folder%\%%~nxF"
    )
)
set "Answer="
set "Folder="

For more information on the used commands open a command prompt window and enter

  • dir /?
  • for /?
  • if /?
  • set /?

to get help for those commands displayed explaining the parameters and syntax. recycle.exe can be also executed with parameter /? to get help for this tool output in console window.

recycle.exe writes error messages not to console, but displays a message box to confirm by user with a button click. That is very uncommon for a console application. And it does not display which file or folder could not be deleted to recycle bin in the error message. So the user reading the error message can just see that something failed, but not what failed.

Mofi
  • 46,139
  • 17
  • 80
  • 143
  • This was really close. While it does do everything specified above, it does not recycle any of the folders within the directory. It gets rid of all the files, preserves desktop.ini, and gives a prompt, but I still need to make sure that it recycles all of the folders within the specified directory as well. For example, After Effects creates a whole bunch of folders with different names as well, but they're not recycled. Any file, however, is. I need to make sure that everything apart from the hidden files are sent to the recycle bin (within the specified directory.) – Laughable Junnyzup Feb 15 '15 at 17:26
  • Alas, neither of your new suggestions do anything. I'm not sure if "delims=" has something to do with it since it's recycling them instead. I'm not sure what "dir /A-H" is referring to. Perhaps there's some information up there that I have to change to specifically match my computer, but using directly what you have given me doesn't do anything once I enter Y for yes in the command prompt. All files and folders still remain. – Laughable Junnyzup Feb 15 '15 at 17:51
  • Okay, I was able to read those suggestions now, so I understand a little more about each part of the script now. However, your third suggestion still leaves all of the files and folders. While I think I understand how it works, I'm still unsure of what's going wrong. – Laughable Junnyzup Feb 15 '15 at 18:10
  • I double click the batch file. This is what the command prompt told me when I had echo on (I just took a screenshot in the brief moment that the window showed up) http://i.imgur.com/kWaHuS5.png gfdsg was just the name of a test text document I was trying to delete, and "Media Cache Files" is the name of a folder that Premiere Pro creates on its own. To me, it doesn't look like anything is going wrong, but I can't really tell. – Laughable Junnyzup Feb 15 '15 at 19:02
  • When I use Pause at the end, I get the same messages in the command window. (I'm actually not sure how to do all of the commands in the command prompt since there are multiple lines). So if you were to use the exact same script but instead use del instead of recycle.exe, would this script work? – Laughable Junnyzup Feb 16 '15 at 15:48