1.

Solve : help with the "RD" command in a .bat?

Answer»

I work at a school and every time a student logs on a PC it creates a profile folder in C:\Documents and Settings. I WOULD like to run a script to delete them all. Eventually there are hundreds of profile folders taking up 4 or more GB of space. If I leave the path as above it will try to delete Administrator, and All Users, then get an error. Can I delete everything in a directory except certain path names, or are there any other idea's for me to try???That would be relatively simple, HERES an outline
Assuming you are in C:\Documents and Settings

Code: [Select]:: iterate through each directory in the directory
For /D %%a in (*.*) do call :KillUser %%a
Goto :EOF

:KillUser
:: %1 holds the name of a folder

:: skip wanted profiles
If "%1"=="Administrator" GoTo :EOF
If "%1"=="All Users" GoTo :EOF

:: etc for all profiles you want to keep

:: now remove the profile
RD /S /Q "%1"
Sorry but there is a bit more to do on this, I dont have time to investigate further
Make sure you check it on a MACHINE where it doesnt matter if you break it!!

It might be that by removing a folder from the list it gets confused, in which case, output the folder list to a file, then use another loop to read the file and delete the profiles from there.

Graham
gpl, this is what I was going to post...

Right. You work in a school. OK. Like we believe you, but what if you're a student planning a prank? (You would not be the first one on here!)

Dias de verano- Why would you even waist your time in the forums on this site when it is meant to ask these kind of questons. Do you get on every post and say "no your not legit....To bad... not gonna help you".??


Every PC whether your at a school, a business, or at home you still have "C:\Documents and Settings" with profiles in it. I'm not asking how you hack a server... I'm simply asking for pointers about a RD script in a MS Dos forum.You sure spell bad for someone who "works in a school", and you show the sort of attitude you expect from a 14 year old.
This doesn't look like a question a hacker might ask, more like how to put something in a start up folder.I'm not an English teacher... I'm in the tech department. Sorry for any spelling errors. I'm not trying to have an attitude of any sort. I'm simply trying to get this figured out to make my job easier. So far I have to two ideas, which I'm not really happy with either.

Idea #1

@echo off
title HS list- local users
rd /s /q "c:\Documents and Settings\user1"
rd /s /q "c:\Documents and Settings\user2"
rd /s /q "c:\Documents and Settings\user3"
rd /s /q "c:\Documents and Settings\user4"
pause
exit

This would work, but it just isn't practical. Our district is very small but still have around 1,150 students. I can copy paste very quickly and would just have to delete Seniors and add 6Th graders every year. Also We have PCs ranging form Dell GX280's all the way down to Dell GX150's, which perform the long task way to slow because it is checking for every student even though the average PC only has between 2 and 3 hundred profiles.

Idea #2

@echo off
md "C:\Move_Here"
pause
rd /s /q "C:\Move_Here"
pause
exit

This idea is slightly more practical. Basically you run the script it creates the "move_Here" folder. You would then have to manually move all the user folders to it. Moving isn't all that slow compared to copying. Then it removes the "Move_Here" folder. Leaving my couple of folders that I need to keep. The biggest problem with this is having to manually move them witch I'm trying to reduce my interaction time with the script.

I should also add we used to just highlight the profiles we wanted to get rid of, then hit delete. Then we would have to empty the recycle bin which took an additional 10 minutes.

As you can see I have some scripting knowledge, but it's not advanced as I'd like. Also know that if I didn't have admin privileges, and I ran a script of this sort, it wouldn't let me delete them. It would say access denied. Once again, thanks for any help I get.It might be better to use VBScript to do that.

Here's one i found by googling...

http://www.wisesoft.co.uk/Scripts/display_script.aspx?id=14

I personally recommend vbscript over batch files for this kind of procedure. It's more healthy.You should look at gpl's idea / code. It looks like it should be pretty efficient and work pretty well.

Or try this:
Code: [Select]@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%a in ('dir "C:\Documents and Settings" /ad-h /b') do (
set deluser=%%a
if "%%a"=="Administrator" set deluser=
if "%%a"=="All Users" set deluser=
if not "!deluser!"=="" echo rd "%%a" /q /s)That should delete everybody except "Administrator", "All Users" and any hidden profiles which are probably system profiles.Use delprof /Q /C:\\

This tool is part of the WindowsServer2003-AdministrationToolsPack.exe, or you can download delprof.exe from the Microsoft web site



Discussion

No Comment Found