Ad:
 
Similar Threads
Nov 13th, 2006
0

recursive delete using a batch file on windows-XP

Expand Post »
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sliver_752 is offline Offline
7 posts
since Nov 2006
Nov 13th, 2006
0

Re: recursive delete using a batch file on windows-XP

batch files are generally pretty simple-minded things, not at all as powerful as *nix shell scripts. For more complicated tasks you would be better off writing a program in some other language, such as C or C++.
Last edited by Ancient Dragon; Nov 13th, 2006 at 4:14 pm.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 4835
Solved Threads: 1778
Still Learning
Ancient Dragon is offline Offline
17,874 posts
since Aug 2005
Nov 14th, 2006
0

Re: recursive delete using a batch file on windows-XP

There should be an option to delete an entire tree, so you wouldn't need to recursively delete it.
Featured Poster
Reputation Points: 1253
Solved Threads: 400
Posting Expert
iamthwee is offline Offline
5,542 posts
since Aug 2005
Nov 14th, 2006
0

Re: recursive delete using a batch file on windows-XP

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:\
Sponsor
Team Colleague
Featured Poster
Reputation Points: 4835
Solved Threads: 1778
Still Learning
Ancient Dragon is offline Offline
17,874 posts
since Aug 2005
Mar 8th, 2007
1

Re: recursive delete using a batch file on windows-XP

Click to Expand / Collapse  Quote originally posted by sliver_752 ...
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.
Reputation Points: 13
Solved Threads: 0
Newbie Poster
vanillabean is offline Offline
1 posts
since Mar 2007
Mar 27th, 2007
0

Re: recursive delete using a batch file on windows-XP

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"
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dgarcia182 is offline Offline
1 posts
since Mar 2007
Apr 16th, 2007
0

Re: recursive delete using a batch file on windows-XP

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.
Reputation Points: 10
Solved Threads: 0
Unverified User
doggfather is offline Offline
2 posts
since Apr 2007
Apr 16th, 2007
0

Re: recursive delete using a batch file on windows-XP

Hrmm Actually. It does work. My bad. I needed single quotes when testing it outside the batch file.
Reputation Points: 10
Solved Threads: 0
Unverified User
doggfather is offline Offline
2 posts
since Apr 2007
Apr 24th, 2007
0

Re: recursive delete using a batch file on windows-XP

I haven't tried batch file but if you want to do this just once you can use normal windows search. Just search .svn and check option search hidden files in advanced options. Then just delete all .SVn's from search results.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jpkeisala is offline Offline
1 posts
since Apr 2007
Apr 28th, 2007
0

Re: recursive delete using a batch file on windows-XP

hi i am new this forum, unable to find where to post my question.
i need a batch file ,should delete oldfiles except last 15 days, means i should retain only last 15 days folder. the folder name is based on date,ex- today folder will be 20070428.pl help.thanks in advane.

thanks
kanyan
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kanyan is offline Offline
1 posts
since Apr 2007
This thread is more than three months old. Perhaps start a new thread instead?
Message:
Previous Thread in Existing Scripts Forum Timeline: How do i?
Next Thread in Existing Scripts Forum Timeline: Any CMS for knowledgebase & support?





About Us | Contact Us | Advertise | Acceptable Use Policy
Build Custom RSS Feed


Follow us on Twitter


© 2010 DaniWeb® LLC