Solved

script to delete subfolder by name

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

791 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