我想比较位于两个不同文件夹中的文件。 我希望仅比较这两个不同文件夹中具有相同名称的文件。
我希望做的是比较两个不同版本的软件,找出已更改的文件数量。
答案 0 :(得分:-1)
这将帮助您获取两个路径的文件:
import java.io.File;
import java.util.*;
public class ListFiles
{
public static void main(String[] args)
{
// First directory path here.
String path1 = ".";
// Second directory path here.
String path2 = ".";
// File class is very important.
// If you did a simple Google search
// Then you would have seen this class mentioned.
File folder1 = new File(path1);
File folder2 = new File(path2);
// It gets the list of files for you.
File[] listOfFiles1 = folder1.listFiles();
File[] listOfFiles2 = folder2.listFiles();
// We'll need these to store the file names as Strings.
ArrayList<String> fileNames1 = new ArrayList<String>();
ArrayList<String> fileNames2 = new ArrayList<String>();
// Get file names from first directory.
for (int i = 0; i < listOfFiles1.length; i++)
{
if (listOfFiles1[i].isFile())
{
fileNames1.add(listOfFiles1[i].getName());
}
}
// Get file names from second directory.
for (int i = 0; i < listOfFiles2.length; i++)
{
if (listOfFiles2[i].isFile())
{
fileNames2.add(listOfFiles2[i].getName());
}
}
// Now compare
// Loop through the two array lists and add your own logic.
}
}
您需要添加自己的逻辑进行比较。 Source
答案 1 :(得分:-1)
我有这个代码,它将目录中的所有文件与特定文件进行比较,以检查目录中是否存在该文件,可以根据您的需要稍微调整一下。它使用commons-io.jar
template <typename U>
class TreeNode_t
{
public:
TreeNode_t<U>* prev;
TreeNode_t<U>* next;
TreeNode_t<U>* parent;
TreeNode_t<U>* children;
//...