Click to See Complete Forum and Search --> : Batch File Command Problem


bigils
October 23rd, 2003, 05:17 AM
I am trying to develop a batch file which deletes user profiles. In our profile directory there are four user profile folders which must
not be deleted but all the rest must be deleted. I am trying to create a batch file that copies the four folders to a new directory and then deletes the rest of the folders in the original directory. So I am wondering in Windows NT and 2000 is there a command that actually deletes folders and subfolders? And is there a command that Copies actual folders from one destination to another? If not is there a command that copies files from subfolders within folders.

Thank you very much for any help,

Matthew

SLiC
October 26th, 2003, 11:23 PM
I don't have a Windows NT system availabel to get details on the required syntax, but I think something like this could work:

----Batch File Begin----
@ECHO OFF
TITLE SLiC Profile Cleanup
COLOR 17

IF EXIST %WINDIR%\Profiles\User1\FlagFile.ext XCOPY %WINDIR%\Profiles\User1\*.* %WINDIR%\SLiC\Profiles\User1\*.* /V /C /I /Q /H /R > NUL
IF EXIST %WINDIR%\Profiles\User2\FlagFile.ext XCOPY %WINDIR%\Profiles\User2\*.* %WINDIR%\SLiC\Profiles\User2\*.* /V /C /I /Q /H /R > NUL
IF EXIST %WINDIR%\Profiles\User3\FlagFile.ext XCOPY %WINDIR%\Profiles\User3\*.* %WINDIR%\SLiC\Profiles\User3\*.* /V /C /I /Q /H /R > NUL
IF EXIST %WINDIR%\Profiles\User4\FlagFile.ext XCOPY %WINDIR%\Profiles\User4\*.* %WINDIR%\SLiC\Profiles\User4\*.* /V /C /I /Q /H /R > NUL

DELTREE %WINDIR%\Profiles /Y

MKDIR %WINDIR%\Profiles

IF EXIST %WINDIR%\SLiC\Profiles\User1\FlagFile.ext XCOPY %WINDIR%\SLiC\Profiles\User1\*.* %WINDIR%\Profiles\User1\*.* /V /C /I /Q /H /R > NUL
IF EXIST %WINDIR%\SLiC\Profiles\User2\FlagFile.ext XCOPY %WINDIR%\SLiC\Profiles\User2\*.* %WINDIR%\Profiles\User2\*.* /V /C /I /Q /H /R > NUL
IF EXIST %WINDIR%\SLiC\Profiles\User3\FlagFile.ext XCOPY %WINDIR%\SLiC\Profiles\User3\*.* %WINDIR%\Profiles\User3\*.* /V /C /I /Q /H /R > NUL
IF EXIST %WINDIR%\SLiC\Profiles\User4\FlagFile.ext XCOPY %WINDIR%\SLiC\Profiles\User4\*.* %WINDIR%\Profiles\User4\*.* /V /C /I /Q /H /R > NUL

REM Written By SLiC
REM Last revised October 26, 2003
-----Batch File End-----

Becareful ... do not assume this is OK as is!!
First .... test on what is safe.
FlagFile.ext referrs to a flag file to use as a check (i.e. KeepMe.TXT)
User# referrs to the profile to be kept.
This batch will fail if run while a user is logged on, as that users profile would be in use. Therefore it would be best to schedule it to run during a time when the users are logged off.

Double check and test, test, test ... before using even once.

Hope this helps