rapport89
rapport89

Reputation: 109

Gradle Copy Task: How can I avoid creating subdirectories while copying subdirectories content

I am trying to copy files from a parent directory which contain multiple sub directories. The required file Tree structure is below:

MachineLogs/XXXXX/*_CORE.txt

MachineLogs/YYYYY/*_CORE.txt

I am using the following code for selecting and copying required files:

    from "$localLogsDir/CoreLogsUos1"
    include '*/*_CORE_*.*'
    into new File(analysisChainDir, 'CORE')
    includeEmptyDirs = false
    exclude { details -> details.file.isDirectory()}

The above snippet is copying the CORE files correctly but it is also copying the directory in which they are present. I can not name the sub-directories as they are created dynamically according to present date.

Upvotes: 1

Views: 917

Answers (1)

Opal
Opal

Reputation: 84756

You can try in the following way (mind the regex, it does not match at the moment):

task copyLogs(type: Copy) {
  from fileTree('logs').filter { it.isFile() && it.name.matches('.*_CORE.*') }
  into 'dist'
  includeEmptyDirs = false
}

Here you can find a demo.

Upvotes: 3

Related Questions