/build/static/layout/Breadcrumb_cap_w.png
03/22/2019 192 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
Eighth 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)