Fixes: #9594 Issue link: https://github.com/spring-projects/spring-integration/issues/9594 The `String.replaceFirst()` for directory with `[]` or `()` leads to a regex execution which does not really replace the root path because of mismatch between regex and file path. Essentially, the `Matcher.quoteReplacement()` does not do the trick we would expect from it. * Use `Path.relativize()` API instead which works in canonical paths and proper file separators **Auto-cherry-pick to `6.3.x` & `6.2.x`**