Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Batch File Help, 'delete all folder
Name: James_C Date: September 24, 2005 at 11:07:22 Pacific OS: Winsods XP Pro CPU/Ram: Pentium M 1.6, 768 RAM
Comment:
Hi,
I need help with a batch file, i need it to delete all folders, subfolders and files from C:\Documents and Settings except for four folders named:
All Users Default User LocalService NetworkService
Name: dtech10 Date: September 26, 2005 at 05:57:58 Pacific
Reply:
Hi LocalService & NetworkService are normally hidden, so would not show up in a dir command. For this to work you'll need Deltree.exe from a Win98 disk. Be carefull it's a powefull command. The Harry Directory is mine, just an example of how it works.
---------- @echo off c: cd "c:\Documents and Settings\" dir *.* /b -o:d | find /v "." > \dirs.txt for /f "tokens=*" %%a in (\dirs.txt) do call :DelDirs "%%a" del \dirs.txt exit /b
:DelDirs %1 set Flag=0 if %1=="All Users" set Flag=1 if %1=="Administrator" set Flag=1 if %1=="Harry" set Flag=1 if "%Flag%"=="0" ( rem Add /y when happy, deltree /y %1 rem No confirmation given deltree %1 ) -----------
0
Response Number 2
Name: James_C Date: September 26, 2005 at 07:23:22 Pacific
Reply:
Cheers dtech10, is there any other way of doing this other than using the deltree.exe file? Really I need a single batch file to do the job.
Thanks again
0
Response Number 3
Name: dtech10 Date: September 26, 2005 at 15:37:38 Pacific
Reply:
Hi James I thought about that myself, it was just easier with deltree.exe. I'll work on it.
0
Response Number 4
Name: dtech10 Date: September 27, 2005 at 06:42:34 Pacific
Reply:
Hi James Try This. -- @echo off c: cd\ cd "c:\Documents and Settings\" dir *.* /b -o:d | find /v "." > \dirs.txt for /f "tokens=*" %%a in (\dirs.txt) do call :DelFiles "%%a" del \dirs.txt exit /b
:DelFiles %1 set Flag=0 if %1=="All Users" set Flag=1 if %1=="Administrator" set Flag=1 if %1=="Harry" set Flag=1 if "%Flag%"=="0" ( cd %1 attrib *.* -r /s cd.. rem change rd %1 /s /q rem for no confirmation rd %1 /s )
0
Response Number 5
Name: James_C Date: September 28, 2005 at 03:14:23 Pacific
Reply:
Thanks dtech10, that worked a treat! Thank you for all your help and time spent doing this!
0
Response Number 6
Name: kpaz Date: October 21, 2005 at 05:51:48 Pacific
Reply:
Thanks, it also worked fine for me :)
But what if I want to NOT delete the logged user's profile ?
Summary: I need help with a batch file, i need it to delete all folders, subfolders and files from C:\Documents and Settings except for five folders named: Administrator All Users Default User LocalService Net...
Summary: Hey! I need batch file that removes all subdirectories from directory. Example: I have directory on my desktop named N152. Its including directorys GT36GS6, GJ36KF and GK2OR5F. I want batch file to e...
Summary: We have a directory c:\temp that act as storage for a directory monitor for printing before it moves files along. Within c:\temp a unique folder name is created along with a inbound and outbound folde...