Batch Delete User Files every 2 Weeks

0

I need a Batch-Script which delete Private User Files every 2 Weeks. User Files Admin, Public and a Domain-Account "dJas" shouldn't be deleted.

This Script crashes Windows

@echo off & setlocal 

set "Verz=C:\Users\" 

set "Behalten1=Administrator" 
set "Behalten2=Public"
set "Behalten3=dJas" 

for /f "delims=" %%i in ('dir /b /ad "%Verz%"^|findstr /v /x /c:"%Behalten1%" /c:"%Behalten2%" /c:"%Behalten3%"') do rd /s /q "%Verz%\%%i" 

echo del /q "%Verz%" 

Ophelia-IT

Posted 2016-01-18T08:30:41.237

Reputation: 1

Your findstr command is wrong. Change rd /s /q "%Verz%\%%i" to echo rd /s /q "%Verz%\%%i" to see why. The findstr is passing every directory in c:\users to rd so you are deleting everything. – DavidPostill – 2016-01-18T09:51:23.017

Note even if you fix it to match the 3 values you are trying to match it will still delete All Users, Default User and Default (English names). I don't think it is a good idea to do that. – DavidPostill – 2016-01-18T09:53:44.693

But I want to do that cause many people are using this pc and save there unnecessary files, so i want to start the script which delete automaticly all unnecessary folders – Ophelia-IT – 2016-01-26T05:53:32.740

<shrug> All Users is used for software that been installed for anyone to run. Individual users don't save their files there. – DavidPostill – 2016-01-26T09:35:46.453

No answers