How to get files and directories name using Gradle?

I have dir in which another task create files and directories so in this dir there are files, directories, subdirectroies, files in them and ect. I want to put all absolute path of files and directories in a list.

def listNames = project.fileTree('dir')

But only the files are included in the list, directories are missing. How to collect all of them?

2 Answers

def names = []
fileTree("baseDir").visit { FileVisitDetails details -> names << details.file.path
}

For further details, see FileTree in the Gradle Javadoc.

1

The shorter version:

def files = fileTree("dirName").filter { it.isFile() }.files.name

Of course it does the same thing.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like