Computing.Net > Forums > Programming > Remove Folders with Batch file

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.

Remove Folders with Batch file

Reply to Message Icon

Name: Daemonbarber
Date: December 5, 2005 at 07:27:17 Pacific
OS: win2k
CPU/Ram: -
Comment:

I'm looking for a way to remove folders (roughly 50 per computer for about 250 computers).

They are all in the same directory on each machine, but there 5 of them that must be kept, 4 are static, the 5th is the same as %username%

I need a way to cycle through each directory within that directory (C:\Test\) and delete the ones that dont meet the above criteria.

Any help would be appreciated!



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: December 5, 2005 at 08:01:32 Pacific
Reply:

Try this:

::==========
c:
cd c:\test
for /f "tokens=*" %%F in ('dir /b/ad') do call :remover %%F
goto :eof

:remover
set workfile=%*
if /i %workfile%==one goto :keepIT
if /i %workfile%==two goto :keepIT
if /i %workfile%==three goto :keepIT
if /i %workfile%==four goto :keepIT
if /i %workfile%==%username% goto :keepIT
rd /s/q %workfile%
:keepIT
goto :eof
::========


If at first you don't succeed, you're about average.

M2


0
Reply to Message Icon

Related Posts

See More


VB6 Mysql remote connecti... binary problem



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: Remove Folders with Batch file

Get last line with batch file www.computing.net/answers/programming/get-last-line-with-batch-file/17019.html

copying folders with batch's www.computing.net/answers/programming/copying-folders-with-batchs/12929.html

Problem with batch file www.computing.net/answers/programming/problem-with-batch-file/13943.html