Windows: delete NUL files with gradle

Running gradle under windows, I cannot delete NUL files created from other tools. For example, running this twice won’t work:

task createNUL << {
    "mkdir tmp".execute()
    "touch tmp/NUL".execute()
  task deleteNUL( type: Delete ) {
    dependsOn createNUL
    delete 'tmp'

My assumption is, that this could be a Java issue, since NUL is a reserved filename:

This doesn’t work too:

  public class Example {
   public static void main( String[] args ) {
         File f = new File( "NUL" );
      } catch( Exception e ) {

Any tips?

As a last resort, you could try an ‘Exec’ task that executes a shell command via ‘cmd.exe’.

Thanks for your reply.

I solved it for now with calling a perl script (perl also auto-created that NUL file while configuring openssl), which deletes the NUL file. It would be nice though, if there was a Gradle/Groovy only solution, since this is easier to debug than an external perl script.

These reserved files are strange though, perl can delete them, cygwin can delete them, Java and File Explorer cannot.