Delete file by command line with different type

3

It has 2 directories, their content is the same, but in one of them there can only be java files

and in the other only files other than java

In the resources folder are those are not java

  

src \ main \ resources> from / s * .java

In the java folder are only the .java files

  

src \ main \ java> del / s ???

??? = all files with extension other than java

    
asked by anonymous 04.04.2014 / 22:22

1 answer

3

The del command does not delete read-only files, unless you force it with /f . So one way to delete all files except .java is to make the .java read-only and then return them.

Make read-only:

cd src\main\java
attrib +r *.java

Delete all files (the .java will stay as they are read-only):

del /q *.*

Being /q so that cmd does not ask if you are sure. Finally, return the .java files to normal:

attrib -r *.java

Another solution would be to compile the .java files to another temporary folder and then return them to the str \ main \ java folder.

Something like:

cd src\main\java
copy *.java TEMP_DIR
del *.* 
copy TEMP_DIR\*.java src\main\java
    
04.04.2014 / 22:38