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

**URL:** <https://discuss.gradle.org/t/copying-and-rename-multiple-files-give-the-same-name-each-of-them/866>\
**Category:** Old Forum Archive\
**Created:** [October 9, 2014, 10:36am UTC](https://discuss.gradle.org/t/copying-and-rename-multiple-files-give-the-same-name-each-of-them/866 "2014-10-09T10:36:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dawid\_Goralczyk](https://avatars.discourse-cdn.com/v4/letter/d/3d9bf3/32.png) [@Dawid\_Goralczyk](https://discuss.gradle.org/u/Dawid_Goralczyk)\
**Post date:** [October 9, 2014, 10:36am UTC](https://discuss.gradle.org/t/copying-and-rename-multiple-files-give-the-same-name-each-of-them/866/1 "2014-10-09T10:36:00Z")

</div>

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:

```gradle
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++
}

```
