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)

Posted by: flip1001 3 years ago
Black Belt

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%"

Posted by: vjaneczko 3 years ago
9th Degree Black Belt

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.

  • i thought about this but i will need exempt some users from the logon script - brighstarcuit 3 years ago
    • Before the del command put
      IF /I "%USERNAME%" EQU "exemptuser1" (exit) - flip1001 3 years ago
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ