Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

DOS Command to Remove Specific Folders in a Directory

Posted on 2012-08-21
8
Medium Priority
?
1,145 Views
Last Modified: 2012-08-21
Back when I was using FrontPage, it created some folders (_vti_cnf and _vti_pvt).  The _vti_cnf folders are in every single folder.  They are not that much (as far as size) but if you have a lot of folders, this basically builds up.

I have been using robocopy to copy the files and the rd (with /s /q) to remove the complete dir.  The rd DOS command is much faster than trying thru windows and I was hoping there was a syntax to remove specific folders.  

On Windows 32bit Ultimate

Thank you!
0
Comment
Question by:coreybryant
  • 5
  • 3
8 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 38316389
Hmm, OK from a cmd.exe prompt:

cd /d C:\root\of\dir
@for /d /r %a in (_vti_*) do @echo rd /q /s "%a"

That will look for all dirs called _vti_* under the dir you start from and run an rd /q /s command against them.

Now... as it stands it will SHOW you all the rd commands.  Remove the word echo once you are happy it is doing the right ones as rd /s/q can be nasty otherwise :-)


Steve
0
 
LVL 29

Author Comment

by:coreybryant
ID: 38317429
That sort of worked.
Frontpage websites and foldersIf you see the icons with the globe, this is (was) what Frontpage considered to be a website.  

It deleted the vti_ folders that were in the folder, but if it was in a "website", it bypassed it
0
 
LVL 29

Author Comment

by:coreybryant
ID: 38317520
I went thru the Window search - it did not find the _vti folders.  So since there were just a few (about 10), I went into each "website" and deleted the _vti_pvt (which was making this a "website".

I then re-ran the command
J:\My Websites>@for /d /r %a in (_vti_*) do @ rd /q /s "%a"

It still did not work.  I shut down the CMD prompt, re-opened in Admin and tried it, it still did not work.

All the folders though no longer have the globe on it.  And Windows search (_vti*) does not find those folders either

And the interesting thing, I did a dir:
J:\My Websites>dir
 Volume in drive J is My Book
 Volume Serial Number is B89C-9B8D

 Directory of J:\My Websites

08/21/2012  07:28    <DIR>          .
08/21/2012  07:28    <DIR>          ..
08/21/2012  07:13    <DIR>          crb
08/21/2012  05:50    <DIR>          www.mymerchantaccountblog.com1

               0 File(s)              0 bytes
               2 Dir(s)  911,634,898,944 bytes free

There are other folders (i.e. coreybryant.com), so I thought I would try to see if I could get into that folder.

J:\My Websites>cd coreybryant.com2

J:\My Websites\coreybryant.com2>

Which worked.   But running
@for /d /r %a in (_vti_*) do @ rd /q /s "%a"

did nothing.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 43

Expert Comment

by:Steve Knight
ID: 38317725
Ahh it won;t work on hidden directories like this and it seems these are.  On some old frontpage dirs of mine the dirs had obviously have been unhidden at some point, but another one I agree did not work.  This does though:

@for /f %a in ('dir /b /ad /s _vti_*') do @echo rd /q /s "%~a"

Again remove "echo " once happy.
0
 
LVL 29

Author Comment

by:coreybryant
ID: 38318120
That also seemed to work.

I basically received this error:
rd /q /s "J:\My"
rd /q /s "J:\My"
rd /q /s "J:\My"
rd /q /s "J:\My"
rd /q /s "J:\My"
rd /q /s "J:\My"
rd /q /s "J:\My"
rd /q /s "J:\My"
rd /q /s "J:\My"
rd /q /s "J:\My"
rd /q /s "J:\My"
rd /q /s "J:\My"

I tried to just rename My Websites to MyWebsites thru windows and it said file was in use (CMD prompt was closed).  

I closed the Window (explorer) and went to a new CMD prompt
J:\>ren J:\My Websites J:\MyWebsites
The syntax of the command is incorrect.

J:\>ren "J:\My Websites" "J:\MyWebsites"
The syntax of the command is incorrect.

I thought maybe re-booting might help to rename the folder if that would be the easiest way?
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 2000 total points
ID: 38318140
Sorry my fault, copy/pasted wrongly between shopping and kids baths :-)

@for /f "tokens=*" %a in ('dir /b /ad /s _vti_*') do @echo rd /q /s "%~a"
0
 
LVL 29

Author Comment

by:coreybryant
ID: 38318255
Sure, blame it on the kids:)

Thanks - that did work!!

Man, I thought my DOS days were over LOL but it does seem to work a lot faster
0
 
LVL 29

Author Closing Comment

by:coreybryant
ID: 38318267
Thanks again!  Fantastic job - wished I could give give you kudos
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

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

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
While working, an annoying popup showing below will come and we cannot cancel or close it form the screen. The error message will come again and again.
This Micro Tutorial will teach you the basics of configuring your computer to improve its speed. It will also teach you how to disable programs that are running in the background simultaneously. This will be demonstrated using Windows 7 operating…
This Micro Tutorial will teach you how to the overview of Microsoft Security Essentials. This is a free anti-virus software that guards your PC against viruses, spyware, worms, and other malicious software. This will be demonstrated using Windows…
Suggested Courses

577 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