?
Solved

Delete a specific subfolder that occurs across a directory structure

Posted on 2013-11-11
3
Medium Priority
?
308 Views
Last Modified: 2013-11-12
Hi,

I need to be able to delete any folders called 'Downloads' within a set of user directories.

Is it possible to look for any occurence of that folder and delete it with a batch file/script?

Many thanks
0
Comment
Question by:itmtsn
[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
3 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 2000 total points
ID: 39638501
This should work...run it in its current form and it should merely display the folder(s) it will remove.
Removing the 'echo' from the last line will cause it to be data destructive, but if it displays the correct folders in the initial test, it sounds like that's what you're after.

@echo off
cd /d c:\users
for /f "tokens=* delims=" %%a in ('dir downloads /s^|find /i "directory of"') do call :process "%%a\Downloads"
goto :eof

:process
set fld=%1
echo rmdir /s /q "%fld:~15% 

Open in new window

0
 

Author Closing Comment

by:itmtsn
ID: 39641013
Many thanks :)
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 39641340
Glad I could help - thanks for the grade :^)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

765 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