/build/static/layout/Breadcrumb_cap_w.png

Scripting Question


Script to delete downloads contents all users

03/22/2019 805 views

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

Comments



Community Chosen Answer

1

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

Answered 03/23/2019 by: flip1001
Fifth Degree Brown Belt

All Answers

0

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.
Answered 03/25/2019 by: vjaneczko
9th Degree Black Belt

  • i thought about this but i will need exempt some users from the logon script
    • Before the del command put
      IF /I "%USERNAME%" EQU "exemptuser1" (exit)
 
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