# Use directory recursively (with exclusions) as input of Exec task

**URL:** <https://discuss.gradle.org/t/use-directory-recursively-with-exclusions-as-input-of-exec-task/50712>\
**Category:** Help/Discuss\
**Created:** [March 24, 2025, 12:58pm UTC](https://discuss.gradle.org/t/use-directory-recursively-with-exclusions-as-input-of-exec-task/50712 "2025-03-24T12:58:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mfplunet](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@mfplunet](https://discuss.gradle.org/u/mfplunet)\
**Post date:** [March 24, 2025, 12:58pm UTC](https://discuss.gradle.org/t/use-directory-recursively-with-exclusions-as-input-of-exec-task/50712/1 "2025-03-24T12:58:21Z")

</div>

I want to write an Exec task that processes the contents of a directory and generates another directory. But if I do `inputs.dir("input")` it seems to only check the modified time of the directory itself, not the contents. That means if I do `touch input/abc` the task does not re-run.

Also, we have some subdirectories of `input` that need to be excluded.

Here is the current task definition:

```groovy
tasks.register('build', Exec) {
    // TODO fix up-to-date checking.
    inputs.dir("$rootDir/input")
    outputs.dir("$rootDir/input/build")

    workingDir "$rootDir/input"
    commandLine "build", "$rootDir/input", "$rootDir/input/build"
}

```

`input/build` as well as `input/other` need to be excluded from the inputs.

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [March 26, 2025, 6:04pm UTC](https://discuss.gradle.org/t/use-directory-recursively-with-exclusions-as-input-of-exec-task/50712/2 "2025-03-26T18:04:08Z")

</div>

Do you mean `touch input/abc` when `abc` does not exist previously and thus you create it, or when it already exists?  
If it already exists, doing a `touch` does not modify the input.  
Gradle by default does not care about timestamps as they are useless.  
If you switch a branch in VCS that changes the file and switch back to the previous branch, the file time will have changed but the contents is still the same.  
98.7% of the tasks out there do not care about the file modified date.  
Gradle uses as inputs fingerprints consisting of the actual contents of files, and eventually paths, depending on configured path sensitivity for the given file.

To exclude `input/build` from the inputs, you probably have to use a `fileTree` and `input.files` instead, something like `inputs.files(fileTree("input").matching { exclude(" **/build/**") })` (not tested thoroughly).  
But if possible it is most probably better to not have the output directory inside the input directory, but somwehere seperate, for example at `layout.buildDirectory.dir("build-output")`.

---

<div class="post-metadata">

**Author:** ![mfplunet](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@mfplunet](https://discuss.gradle.org/u/mfplunet)\
**Post date:** [March 27, 2025, 10:33am UTC](https://discuss.gradle.org/t/use-directory-recursively-with-exclusions-as-input-of-exec-task/50712/3 "2025-03-27T10:33:06Z")

</div>

OK fileTree is the solution I think, thanks.
