Solved

script to delete subfolder by name

Posted on 2014-01-19
2
578 Views
Last Modified: 2014-01-19
Hi I have over 1000 movie folders, and in each is a folder named trailers. I am setting up streaming for my tv, and don't need the trailers folders. May I please have a script that will cycle thru the main folder called movies, and look inside each subfolder, then delete any folders called trailers. Here is structure sample
Movies\Her\trailers\trailer.avi
Movies\End Game\trailers\trailer.avi
I would like the trailers folders and its content (trailer.avi) to be deleted. Thanks in advance.
0
Comment
Question by:xzay1967
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 19

Expert Comment

by:bevhost
ID: 39792749
Depends on version
see http://en.wikipedia.org/wiki/DELTREE

try

rmdir /s/q folder
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 39792807
Try this.  Changed the cd line to your right base directory.  It then works down all directories under that looking for ones called trailers.  it then does an RD quietly of that and all subdirs of trailers.

At the moment it will show you on the screen what it will do.  remove the capital word ECHO to actually do it...

Steve

With log of what it is doing.. the line starting with lowercase echo you can remove or whatever, will just log what it does and if there were any errors.

@echo off
cd /d "c:\my-movies"
(for /f "tokens=*" %%d in ('dir /ad /b /s trailers') do (
  ECHO rd /s /q "%%~d"
  echo Deleting %%~d - Error %errorlevel%
)) > log.txt

Open in new window


Without log:

@echo off
cd /d "c:\my-movies"
for /f "tokens=*" %%d in ('dir /ad /b /s trailers') do (
  ECHO rd /s /q "%%~d"
)

Open in new window

0

Featured Post

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question