java - 如何引用不同目录子结构中的文件/目录?

标签 java recursion path directory

我需要递归比较用户选择的两个文件夹(源和目标)的内容(包括所有子文件夹)。内容必须放入 TreeViews 中,这将显示其中的文件/目录如何使用某种颜色标记或类似的方式相互比较。关系是:

Exists in source, but not in target -> new, copy over to target
Exists in target, but not in source -> deleted, delete from the target
Exists in both, but binary unequal -> changed, copy over from source
Exists in both, and is binary equal -> unchanged, leave be

然而,问题是在递归地遍历其中一个目录时以某种方式引用另一个目录。示例:

Source: C:\somewhere\fooSource
Target: C:\somewhereElse\barTarget

现在,对源文件夹的递归调用找到了 C:\somewhere\fooSource\aSubfolder。如何让 Java 将路径 C:\somewhereElse\barTarget\aSubfolder 放在一起,以便程序可以检查是否存在或进行二进制比较(如果它是文件)?

编辑,一些实现的框架:

@FXML
private void handleCompareButton() {
    if (sourceFile.exists() && targetFile.exists() && !sourceFile.equals(targetFile)) {
        for (File i : sourceFile.listFiles()) {
            if (i.isFile()) {
                if (/*the equivalent file in the other directory**/.exists()){
        /*do the checks for binary equality**/
                }
            }
/*some recursive calls to another function in case it's a directory**/
        }
    }
}

最佳答案

Google 是你的 friend :).. 这是我发现与你需要的非常相似的东西...... http://www.java2s.com/Tutorial/Java/0180__File/Utilityclassforsynchronizingfilesdirectories.htm

关于java - 如何引用不同目录子结构中的文件/目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34061512/

相关文章:

java - 如何使用 Eclipse 将 Maven 项目导出为 exe(或 jar)文件?

javascript - 遍历我的主目录时出现 EPERM 错误的原因是什么?

java - 使用递归查找句子中最长的单词(Java)

optimization - 如何编写通用的内存功能?

events - 在事件操作中突出显示 SVG <g> 中的多个路径元素

java - 升级到 hibernate 5.1 时出现 QuerySyntaxException

Web 应用程序中的 Java 并发多线程算法 - 比预期慢

javax.servlet.ServletException : Error creating bean - Invocation of init method failed; nested exception is javax. 持久性.PersistenceException

php - 在php中包含文件

windows - 在 Windows 上从命令行轻松运行程序