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%"
Your
findstr
command is wrong. Changerd /s /q "%Verz%\%%i"
toecho rd /s /q "%Verz%\%%i"
to see why. The findstr is passing every directory inc:\users
tord
so you are deleting everything. – DavidPostill – 2016-01-18T09:51:23.017Note even if you fix it to match the 3 values you are trying to match it will still delete
All Users
,Default User
andDefault
(English names). I don't think it is a good idea to do that. – DavidPostill – 2016-01-18T09:53:44.693But 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