【问题标题】:How to refer to a file/dir in a different directory substructure?如何引用不同目录子结构中的文件/目录?
【发布时间】:2016-03-07 19:15:19
【问题描述】:

我需要递归比较用户选择的两个文件夹(源和目标)的内容(包括所有子文件夹)。内容必须放入 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**/
        }
    }
}

【问题讨论】:

  • 到目前为止你做了什么?你能给我们看一些源代码吗?

标签: java recursion path directory


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-28
    • 2019-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多