Question : How to delete all files and folders in users MyDocs

I have a client that is a school.  They use folder redirection and all the MyDocs are on a W2K3 server in Class directories.  They want to delete all the data in the students MyDocs but retain the folders for My Pictures, My Shapes (Visio) and a custom school folder.  How do we go about deleting all these files and folders and still retain the folders needed and correct folder permissions?  I figured there is a script or a program that could do this.

Answer : How to delete all files and folders in users MyDocs

Hey Sorry about that issue, I am super tired very long day and very little sleep there were several stupid typos.

I was falling asleep trying to fix it, but I did actually test the script this time which I was too bust to do today while at work, so I know it functions correctly under windows 7 any way.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
::------------------------------------------------------------------------------------------------::
:: Script: MyDocsDelete.Bat		                                            				 	  ::
:: Version: 1.4                                                                                   ::
:: Copyright: Ben Personick                                                                       ::
:: Date: 2010-07-08                                                                               ::
::                                                                                                ::
::                                                                                                ::
:: Desc: Deletes all files and folders underneath the mydocuments folders of multiple users.	  ::
::	  DOES NOT Delete the My Pictures or My Shapes Folder, ONLY the Files within them			  ::
::																								  ::
::------------------------------------------------------------------------------------------------::
:Begin
@Echo Off

::------------------------------------------------------------------------------------------------::
:: This section sets up default variable settings and sets the logging directory and file name.   ::
::------------------------------------------------------------------------------------------------::
:Start-Prep
	CALL :Start-Set-Date
	SET Preamble=MyDocsDelete --
	::--------------------------------------------------------------------------------------------::
	:: Sets Relative Paths used to search later.												  ::
	::--------------------------------------------------------------------------------------------::
	SET SDir=C:\Empty
	SET Class=\\PYLON\Some Folder\Class
	
	::--------------------------------------------------------------------------------------------::
	:: This Section Sets up logging variables.													  ::
	::--------------------------------------------------------------------------------------------::
	SET IDir=C:\MyDocsDelete\Logs
	SET ILog=ILog_%TDate%_%TTime%.Log
	SET IDL=%IDir%\%ILog%
	:Start-IDir
		ECHO %Preamble% Checking For %IDir%
		IF EXIST %IDir% CALL :Start-Echo "%Preamble% IDir %IDir% -- Found!"
		IF EXIST %IDir% GOTO End-IDir
		ECHO %Preamble% Creating %IDir%
		mkdir %IDir%
	:End-IDir

	::--------------------------------------------------------------------------------------------::
	:: This Section Sets Default Values for match variables, don't change except for testing.	  ::
	::--------------------------------------------------------------------------------------------::
	REM None Needed.

:End-Prep



:Start-Main
	Call :Start-Echo "Begining Main Section ON %TDate% AT %TTime%"
	
	:Start-MKSDir1
		ECHO %Preamble% Checking For "%SDir%\My Shapes"
		IF EXIST "%SDir%\My Shapes" CALL :Start-Echo "SDir %SDir%\My Shapes -- Found!"
		IF EXIST "%SDir%\My Shapes" GOTO End-MKSDir1
		ECHO %Preamble% Creating "%SDir%\My Shapes"
		mkdir "%SDir%\My Shapes"
	:End-MKSDir1

	:Start-MKSDir2
		ECHO %Preamble% Checking For "%SDir%\My Pictures"
		IF EXIST "%SDir%\My Pictures" CALL :Start-Echo "SDir %SDir%\My Pictures -- Found!"
		IF EXIST "%SDir%\My Pictures" GOTO End-MKSDir2
		ECHO %Preamble% Creating "%SDir%\My Pictures"
		mkdir "%SDir%\My Pictures"
	:End-MKSDir2
	
	:Start-RoBoCopy-Process
	REM Loop though all user subfolders in base folder
	REM for /D %D in ("C:\Some Folder\Class\*" ) DO echo %D
	For /D %%D IN ("%Class%\*" ) DO Call :Start-RoboCopy-Loop "%%D"
	REM For /D %%D IN ('%Class%') DO Call :Start-RoboCopy-Loop "%%D"
	GOTO End-RoboCopy-Loop
		:Start-RoboCopy-Loop
			SET TDir=%~1
			REM  Echo  "The 1 Variable is %1 TDir=%TDir%"
			CALL :Start-Echo "Now Deleting Files and Folders in: %TDir%\My Documents"
			RoboCopy "%SDir%" "%TDir%\My Documents" * /NoCopy /PURGE /S /LOG+:%IDL% /TEE /NP
			GOTO :EOF
		:End-RoboCopy-Loop
	CALL :Start-Set-Date
	CALL :Start-Echo "RoboCopy Processes Completed! ON %TDate% AT %TTime%"
	:End-RoBoCopy-Process
	
:End-Main
GOTO :EOF


GOTO End-Subs
GOTO :EOF
:Start-Subs
	GOTO :End-Set-Date
	:Start-Set-Date
		SET TDate=%date:~10,4%-%date:~4,2%-%date:~7,2%
		SET TTime=%Time:~0,2%.%Time:~3,2%.%Time:~6,2%
		GOTO :EOF
	:End-Set-Date
	GOTO End-Echo
	:Start-Echo
		Set TEcho=%~1
		ECHO %Preamble% %TEcho% --
		ECHO %Preamble% %TEcho% -- >> %IDL%
		GOTO :EOF
	:End-Echo

:End-Subs

:End
Random Solutions  
 
programming4us programming4us