Created
December 17, 2013 18:20
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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