Avatar of Yogeshup
Yogeshup asked on

How to delete subdirectory's using batch file!

Hi,

I'm looking for a .bat/.cmd file which able to delete all sub-directory's for given path in the parameter, it should delete all sub-directory's "except" the folder which is having today's date ie...

Sample sub-directory's

20080514
20080515
20080516
20080517

Let say we pass the Path to .bat file "C:\MyDirecotry"  -- now this program should delete all subdirectory's under this folder but except the folder having todays date! ie "20080517"

we assume today is 17th May 2008.

Thanks in advance


Windows BatchMicrosoft DOS

Avatar of undefined
Last Comment
devil_himself

8/22/2022 - Mon
Hendo1973

The DOS deltree command will delete an entire directory tree.
ASKER
Yogeshup

ya i know that, but how to prevent a folder having todays day!
ASKER CERTIFIED SOLUTION
oBdA

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
devil_himself

try this
assumes date format --> day month\date\year

usage %0 path to folder in double quotes

example -->  delsub "d:\tmp"
@echo off
for /f "tokens=*" %%a in ('dir "%~1" /ad /b') do echo "%%~na" | find "%date:~-4%%date:~4,2%%date:~7,2%" > nul || rmdir /s /q "%~1\%%a"

Open in new window

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy