Script to delete downloads contents all users
I am looking to create a script to delete the contents of the downloads folder for all users on a workstation. Not the folder but its contents. .bat is fine. I cant seem to find the magic combo by googling. thanks
0 Comments
[ + ] Show comments
Answers (2)
Please log in to answer
Posted by:
flip1001
5 years ago
I wrote this now but haven't tested it. So, if it damages your systems you're on your own.
@echo off
REM Assumes robocopy is installed
REM dummyFolder variable is an empty folder
REM that robocopy will use to clear the downloads folders
set profileFolder=C:\Users
set dummyFolder=%tmp%\dummyFolder-%random%
if exist "%dummyFolder%\." (exit 1)
mkdir "%dummyFolder%"
if not exist "%dummyFolder%\." (exit 1)
for /d %%a in ("%profileFolder%\*") do (
if exist "%%a\Downloads\." (
Echo Clearing downloads of %%a\Downloads
REM take the echo command off for production
echo robocopy "%dummyFolder%" "%%a\Downloads" /MIR
)
)
REM delete dummy folder
rd /s /q "%dummyFolder%"
Comments:
-
thanks - brighstarcuit 5 years ago
Posted by:
vjaneczko
5 years ago
You could also add a line to the logon script which would be executed by each user when they logon:
del %USERPROFILE%\downloads\*.* /s/q
It wouldn't delete any & all downloads folders at the same time but it would handle the current user, whenever they logged on.
Comments:
-
i thought about this but i will need exempt some users from the logon script - brighstarcuit 5 years ago
-
Before the del command put
IF /I "%USERNAME%" EQU "exemptuser1" (exit) - flip1001 5 years ago