diff --git a/src/main/java/org/apache/commons/io/FileUtils.java b/src/main/java/org/apache/commons/io/FileUtils.java index 7c4a9913fce..9d718d8d81c 100644 --- a/src/main/java/org/apache/commons/io/FileUtils.java +++ b/src/main/java/org/apache/commons/io/FileUtils.java @@ -687,8 +687,7 @@ public static void copyDirectory(final File srcDir, final File destDir, final Fi // Cater for destination being directory within the source directory (see IO-141) List exclusionList = null; final String srcDirCanonicalPath = srcDir.getCanonicalPath(); - final String destDirCanonicalPath = destDir.getCanonicalPath(); - if (destDirCanonicalPath.startsWith(srcDirCanonicalPath)) { + if (destDir.getCanonicalFile().toPath().startsWith(srcDirCanonicalPath)) { final File[] srcFiles = listFiles(srcDir, fileFilter); if (srcFiles.length > 0) { exclusionList = new ArrayList<>(srcFiles.length);