narrow default width wide
colour style colour style colour style colour style

Purging redirected My Documents Recycle Bins from file servers

I'm being lazy on this one. This is from an e-mail I just sent out to the technical staff where I am currently consulting

---------------------------------------------------------------------

Here's another dangerous one. This is a simple two-line batch file that will delete all the files in the Recycle Bin in each of your user's UserHome folders. This was requested in last week's meeting.


for /d %%i in (\\s009-ns5\ssmr\userhome\a*) do @echo rem rd /q/s "%%i\my documents\recycler"
pause


The text in green needs to be the path to your UserHome folder.

The text in red is the wildcard for which user folders you want to process. This example will just process the folders that begin with the letter "A". You could put in "*" to run against all accounts or you could go the other route and put in a full username to just process a single folder (might be useful if you want to try it out).

The text in blue needs to be removed before the script will actually do anything. The echo means it will just show the command that it would run instead of actually running it. The 'rem' is just another thing I put in there to make sure no one accidentally ran it without understanding how it works.


Basically, it will run the "RD /S/Q" command on each 'recycler' folder in UserHome\%username%\My Documents.

Example of what it does:

rd /q/s "\\s009-ns5\ssmr\userhome\AEGANN\my documents\recycler"
rd /q/s "\\s009-ns5\ssmr\userhome\AMAGOS\my documents\recycler"
rd /q/s "\\s009-ns5\ssmr\userhome\AMANWA\my documents\recycler"
rd /q/s "\\s009-ns5\ssmr\userhome\APRESL\my documents\recycler"


You may or may not remember, but it is impossible to delete files from the Recycle Bin based on deletion date or anything like that. Unless you go through the GUI, it is an all or nothing affair. You can read the article at http://support.microsoft.com/kb/136517/EN-US/ if you want to understand why this is. Basically, if we selectively delete files, the index gets corrupt and none of the files will be visible in the GUI Recycle Bin (even though the file is actually still there). And, trust me, it is all but impossible to try to modify that index file manually. :)

Also, if you haven't ever used the FOR command, it can be your best friend for automating a repetitive task. It can be used in a lot of different ways other than processing multiple subfolders. (Here's where I referenced some samples they could review--I will put them at the bottom of the post) There isn't any great documentation explaining each sample but most of them are fairly easy to understand. But, the FOR command can be extremely powerful so please contact someone before using it if you aren't 100% sure what you are doing. Just running "FOR /?" from the command prompt will give you a lot of info on it (probably more info that you want to know...)

 

SAMPLES:

REM Exporting group membership
global "G046-Codefinder" ds >c:\codefinder.txt

REM TO process each entry in a text file
for /f %%i in (c:\codefinder.txt) do echo cacls \\%%i\c$\windows\hbowem32.ini /E /G Users:C

REM To return just the folder names for all subfolders in a folder
for /d %%i in (\\s009-ns5\ic\userhome\*.*) do @echo %%~ni

REM To process each subfolder in a specific folder (returns entire path)
for /d %%i in (\\s009-ns5\ic\userhome\*.*) do @echo %%i

REM Example of setting a "fake" delimiter so everything is assigned to %%i
for /f "tokens=1-20 delims=#" %%i in ('dir c:\*.*') do @echo %i%

REM Example that uses multiple variables based on the default delimiters (tab and space)
for /f "tokens=1-20" %i in ('dir c:\*.*') do @echo %i %j %k

REM Example that shows returning specific tokens using a custom delimiter
for /f "tokens=1-3 delims=, " %i in (c:\test.csv) do @echo %k   %j