Solved

script to delete subfolder by name

Posted on 2014-01-19
2
564 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
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

809 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