Solved

Delete a specific subfolder that occurs across a directory structure

Posted on 2013-11-11
3
298 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
  • 2
3 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
A safe way to clean winsxs folder from your windows server 2008 R2 editions
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

867 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