::------------------------------------------------------------------------------------------------::
:: 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
|