Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 807
Xelian Avatar asked Mar 11 '14 07:03

Xelian


People also ask

What is the file name built by Gradle?

Gradle uses the name build. gradle as the default name for a build file. If we write our build code in a file build. gradle then we don't have to specify the build filename when we run tasks.

What is .Gradle directory?

The Gradle user home directory ( $USER_HOME/.gradle by default) is used to store global configuration properties and initialization scripts as well as caches and log files.

Where is the build directory in Gradle?

get global build path from environment variable or fallback to build directory inside project directory; include project group in path, this makes path more unique especially if you have several projects with the same name.

Which of the following files is a Gradle file?

gradle file is located in each module of the android project. This file includes your package name as applicationID , version name(apk version), version code, minimum and target sdk for a specific application module.


2 Answers

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

For further details, see FileTree in the Gradle Javadoc.

like image 73
Peter Niederwieser Avatar answered Oct 07 '22 08:10

Peter Niederwieser


The shorter version:

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

Of course it does the same thing.

like image 25
kasiacode Avatar answered Oct 07 '22 07:10

kasiacode