•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Existing Scripts section within the Web Development category of DaniWeb, a massive community of 391,697 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,139 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Existing Scripts advertiser: Web Code Converter
Views: 31096 | Replies: 10
![]() |
| |
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,548
Reputation:
Rep Power: 36
Solved Threads: 860
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,548
Reputation:
Rep Power: 36
Solved Threads: 860
yes there is that option, but the way I understand it is that he only wants to delete selected files/folders, not all of them. Use "rd /s" command to remove all the files and directories in the current tree. warning: do not do this from root directory such as c:\
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
•
•
Join Date: Mar 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
Hi all
I am trying to write a batch file which would recursively delete folders with a specific name inside a tree. i am just not able to do that. Please help me.
thanks for your help in advance
This will do the trick:
FOR /F "tokens=*" %%G IN ('DIR /B /AD /S *.svn*') DO RMDIR /S /Q %%G
If you're thinking WTF?:
DIR /B /AD /S *.svn*
lists all files that are named ".svn"
/B makes the output "bare" with nothing but the file name
/AD only lists directories
/S recurses subdirectories to include their contents if they match the listing criteria
RMDIR /S /Q [path/name]
deletes the directory [path/dir] and all of it's children
FOR /F processes each item (in this case directories) in the set IN ('[command]') by executing the DO [command]
%%G is a parameter, which in this example is a directory name
"tokens=*" says that all the characters output in a line (i.e. by the dir command) are assigned to the parameter %%G
See the Microsoft Command Line Reference for more on FOR:
Last edited by vanillabean : Mar 8th, 2007 at 2:00 am.
•
•
Join Date: Mar 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
Thanks for the script, it works great! Some of my directories would not delete due to having spaces in the directory names, for instance C:\out\IQSv3\Portal\Web References\Service\.svn. Adding quotes around the %%G fixed this problem.
FOR /F "tokens=*" %%G IN ('DIR /B /AD /S *.svn*') DO RMDIR /S /Q "%%G"•
•
Join Date: Apr 2007
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
I am having issues with this command... I get the following error when trying to use this:
D:\Backup to Disk # 1>FOR /F "tokens=*" %%G IN ('DIR /b /ad /s "d:\Backup to Disk # 1\img*"') DO RMDIR /S /Q "%%G"
%%G was unexpected at this time.
It is referencing the first instance of that. I do not know why... any ideas? I am trying this on server 2003 to remove a backup to disk instance once it is backed up to a tape incase anyone wondered.
D:\Backup to Disk # 1>FOR /F "tokens=*" %%G IN ('DIR /b /ad /s "d:\Backup to Disk # 1\img*"') DO RMDIR /S /Q "%%G"
%%G was unexpected at this time.
It is referencing the first instance of that. I do not know why... any ideas? I am trying this on server 2003 to remove a backup to disk instance once it is backed up to a tape incase anyone wondered.
•
•
Join Date: May 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
Doggfather - Im getting the same error - when applying single quotes from command line. Does anyone know what Im doing wrong...Ive tried:
1. FOR /F "tokens=*" %%G IN ('DIR /B /AD /S *.svn*') DO RMDIR /S /Q %%G
2. FOR /F "tokens=*" %%G IN ('DIR /B /AD /S *.svn*') DO RMDIR /S /Q '%%G'
3. FOR /F "tokens=*" %%G IN ('DIR /B /AD /S *.svn*') DO RMDIR /S /Q "%%G"
4. FOR /F "tokens=*" '%%G' IN ('DIR /B /AD /S *.svn*') DO RMDIR /S /Q "%%G"
5. FOR /F "tokens=*" "%%G" IN ('DIR /B /AD /S *.svn*') DO RMDIR /S /Q "%%G"
6. FOR /F "tokens=*" '%%G' IN ('DIR /B /AD /S *.svn*') DO RMDIR /S /Q %%G
7. FOR /F "tokens=*" "%%G" IN ('DIR /B /AD /S *.svn*') DO RMDIR /S /Q %%G
No matter what I do i get:
%%G was unexpected at this time.
1. FOR /F "tokens=*" %%G IN ('DIR /B /AD /S *.svn*') DO RMDIR /S /Q %%G
2. FOR /F "tokens=*" %%G IN ('DIR /B /AD /S *.svn*') DO RMDIR /S /Q '%%G'
3. FOR /F "tokens=*" %%G IN ('DIR /B /AD /S *.svn*') DO RMDIR /S /Q "%%G"
4. FOR /F "tokens=*" '%%G' IN ('DIR /B /AD /S *.svn*') DO RMDIR /S /Q "%%G"
5. FOR /F "tokens=*" "%%G" IN ('DIR /B /AD /S *.svn*') DO RMDIR /S /Q "%%G"
6. FOR /F "tokens=*" '%%G' IN ('DIR /B /AD /S *.svn*') DO RMDIR /S /Q %%G
7. FOR /F "tokens=*" "%%G" IN ('DIR /B /AD /S *.svn*') DO RMDIR /S /Q %%G
No matter what I do i get:
%%G was unexpected at this time.
Last edited by jdcravens : May 5th, 2007 at 5:23 pm.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Existing Scripts Marketplace
•
•
•
•
apple browser cd choose command computer console crack debian defender dell development download drm explorer fiji install internet leopard linux microsoft mobile news office open operating os parliament photo registry root security server software source spyware survey system technology tiger torvalds tweaks ubuntu unix upgrade vista windows windows update windows vista xp
- How can i suppress a user prompt while running a batch file in windows 2000 machin (Windows NT / 2000 / XP / 2003)
- How can i capture a crash while running a batch file? (Windows NT / 2000 / XP / 2003)
- Creating Batch Files in WIndows XP (Windows NT / 2000 / XP / 2003)
Other Threads in the Existing Scripts Forum
- Previous Thread: se friendly Database content management
- Next Thread: vBulletin + Wordpress sitemap



Hybrid Mode