Skip to content

Instantly share code, notes, and snippets.

@lifuzu
Created December 17, 2013 18:20
Show Gist options
  • Save lifuzu/8009968 to your computer and use it in GitHub Desktop.
Save lifuzu/8009968 to your computer and use it in GitHub Desktop.
To check if a folder exists or not, and to write to the file
//To check if a folder exists or not, and to write to the file
// Create a File object representing the folder 'A/B'
def folder = new File( 'A/B' )
// If it doesn't exist
if( !folder.exists() ) {
// Create all folders up-to and including B
folder.mkdirs()
}
// Then, write to file.txt inside B
new File( folder, 'file.txt' ).withWriterAppend { w ->
w << "Some text\n"
}
@3c71
Copy link

3c71 commented Jun 30, 2021

Not sure which version of gradle you're using here, but I confirm the folder.exists() doesn't work on gradle 7.1 with plugin 4.2.1. Always false no matter what

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment