Solved

script to delete subfolder by name

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now