Copying and rename multiple files give the same name each of them

I have to write gradle task which will be copying files. Files are stored at tests/[Name]/test.txt and for each Name I want to create numbered directory /tested/test00/, /tested/test01/ etc. and in each catalog should be one file (test.txt from source folder renamed to test00, test01 etc.) I have the code, but behavior is strange… It creates correct directories /tested/test00 etc. but all files in each directory have the same name… test06. So number in directory is correct but in file name it isn’t.

My code is:

int copyTaskIterator = 0
int testIterator = 0
 ...
  sources.each { mySource ->
    task "myCopyTask$copyTaskIterator"(type: Copy)
    nameSuffix = String.format("%02d", testIterator)
    fromPath = 'tests/'+mySource+'/test.txt'
    toPath = "tested/test"+nameSuffix
      tasks."myCopyTask$copyTaskIterator".from fromPath
    tasks."myCopyTask$copyTaskIterator".into toPath
    tasks."myCopyTask$copyTaskIterator".rename { fileName ->
        fileName.replace '.txt', nameSuffix
    }
      preBuild.dependsOn tasks."myCopyTask$copyTaskIterator"
    copyTaskIterator++
    testIterator++
}