views:

636

answers:

4

I'm writing a batch file that needs to delete all the files in a certain dir and all of it's subdirectories except those of a specific type.

How can I do this?

+1  A: 

You might try something along the lines of

for /f "usebackq delims=" %i in (`dir /s /b *`) do if not %~xi==.txt del %i

For your question in the comment you can try the following:

robocopy source_folder target_folder *.java /s

or

xcopy *.java target_folder /s

which keeps the directory structure but only copies .java files.

Joey
A: 

Try researching here.

Although it doesn't give you exactly what you are asking, I would say it's a good starting point.

Eppz
+1  A: 

safest way is to copy all the files you do want and delete the rest.
XCOPY *.java c:\new_directory /s

The /s copies subdirectories

Martin Beckett
+1  A: 

I'm using the solution found here: http://stackoverflow.com/questions/558648/how-can-i-delete-all-files-subdirs-except-for-some-files-in-dos/558662

give it a go :)