Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 604
  • Last Modified:

script to delete subfolder by name

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
xzay1967
Asked:
xzay1967
1 Solution
 
bevhostCommented:
Depends on version
see http://en.wikipedia.org/wiki/DELTREE

try

rmdir /s/q folder
0
 
Steve KnightIT ConsultancyCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now