[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Delete a specific subfolder that occurs across a directory structure

Posted on 2013-11-11
3
Medium Priority
?
310 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 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

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
A safe way to clean winsxs folder from your windows server 2008 R2 editions
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…
Suggested Courses

873 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