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?
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?
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.
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
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 :)