Computing.Net > Forums > Programming > Batch File Help, 'delete all folder

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

Reply to Message Icon

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

Any help greatly appreciated

Thanx



Sponsored Link
Ads by Google

Response Number 1
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

Related Posts

See More



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 ?

Thanks in advance

Knowledge is power


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch File Help, 'delete all folder

Remotely Run Batch File from List www.computing.net/answers/programming/remotely-run-batch-file-from-list/17266.html

Batch file to delete unknown folder www.computing.net/answers/programming/batch-file-to-delete-unknown-folder/19956.html

Batch file to delete empty folders www.computing.net/answers/programming/batch-file-to-delete-empty-folders/15992.html