I am writing a script that will remove all of the user accounts on a computer. Currently the code is:
rmdir /s /q "\\%computername%\c$\Documents and Settings\"
This removes all folders (user windows profiles) under the documents and settings folder. The problem is this also removes the "All Users" folder and the "Default User" folders as well. I need a way to remove all other folders than these two folders. The user ID's for each computer will vary so it wont be as simple as just deleting specific folders.
Any thoughts?
Delete all folders in a folder except two
Moderator: DosItHelp
Re: Delete all folders in a folder except two
You could try this
If you think it would work, then remove the ECHO command to do the job.
Regards
aGerman
Code: Select all
@echo off &setlocal
pushd "\\%computername%\c$\Documents and Settings\" ||goto :eof
for /f "delims=" %%a in ('dir /ad /b ^| findstr /b /i /v /c:"all users" ^| findstr /b /i /v /c:"default user"') do (
ECHO rmdir /s /q "%%a"
)
popd
pause
If you think it would work, then remove the ECHO command to do the job.
Regards
aGerman
Re: Delete all folders in a folder except two
aGerman wrote:'dir /ad /b ^| findstr /b /i /v /c:"all users" ^| findstr /b /i /v /c:"default user"'
this block may be shorter, and hidden folders (LocalService, NetworkService) must be exclude:
Code: Select all
'dir /ad-h/b^| findstr /xivc:"all users" /c:"default user"'