PDA

View Full Version : Removing all documents and settings folders (except admin and all users (WXP-Pro)



PsyMan
06-15-2006, 06:36 AM
Hi, I have a network of about 30 PC's that use an Open Directory Domain controlled by a Mac Server. We have 200 students and every time a student logs in they get a local copy of their home folder transferred to the PC, after a few weeks of use this really takes up too much space and in the case of the older PC's it renders them unusable. What I need is to create a log off script or executable script that will delete every folder and file inside of the documents and settings folder EXCEPT the admin and all users folder. it also needs to do it silently and over ride any locked or in use errors that might halt its functionality, I could then schedule it to run every evening and save myself a huge amount of tedious deleting. Any help would be much appreciated

motoflop
06-23-2006, 05:13 AM
Here is sample script which currently doesn't actually delete anything unless you remove "echo" from line "echo rd /q /s %prof%". What this script does:

- goes to c:\Documents and Settings
- lists all sub directories
- for each directory call subroutine "remover" to check and delete that folder
- subroutine checks that no special folders are removed

Note that some folder names are checked with syntax like " if /i "%prof:~0,5%"=="admin" ". This does caseinsesitive comparison for first 5 characters of checked name. Some computers might have Administrators profile stored for example to folder Administrator.COMPUTERX. Simple check " if /i "%1"=="administrator" " would not detect these names. Similar check is performed for LocalService and NetworkService. Of course if all deletable user folder names are like student123, you could use check like " if /i not "%prof:~0,7%"=="student" goto :EOF " to allow deleting only folder names beginning of "student".


@echo off
rem Delete user foders under c:\Documents and Settings
setlocal
cd c:\Documents and Settings
for /d %%i in (*.*) do call :remover %%i
endlocal
goto :EOF

:remover
rem Skip "All Users" and "Default User" profiles
if /i "%1"=="all" goto :EOF
if /i "%1"=="default" goto :EOF
set prof=%*
rem Skip some necessary profiles
if /i "%prof:~0,5%"=="admin" goto :EOF
if /i "%prof:~0,5%"=="local" goto :EOF
if /i "%prof:~0,7%"=="network" goto :EOF
echo rd /q /s %prof%
goto :EOF


This script works on WXP and W2003 when command extensions are active and usually they are. Save the script with .BAT or .CMD extension. To get more information about commands and special syntaxes I have used, type these commands:

SETLOCAL /?
GOTO /?
IF /?
SET /?
CALL /?
FOR /?