-1

Utility to compare two directories & give total number of files it should show the duplicates and an option to delete those duplicates.

I want to write a Java Utility that compare two directory and gives a report of the following the total number of files and directory within it and if there are any duplicate files or sub directory, it should show the duplicates and an option to delete those duplicates along with UI. I am able to write the code for comparing two files with size but i want the file to compared with the all types of extensions like .pdf,.jpeg,.bmp,.doc,.mp3,.avi etc.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
user5390
  • 43
  • 9
  • What do you determine as a duplicate? Name? Size? Content? You could start by taking a look at [`File`](http://docs.oracle.com/javase/7/docs/api/java/io/File.html) or the newer [Path Class](http://docs.oracle.com/javase/tutorial/essential/io/pathClass.html) – MadProgrammer Sep 24 '13 at 05:28
  • Hi friend duplicate means it should compare the file type or mime type for eg-.jpeg,.doc,.p3 – user5390 Sep 24 '13 at 05:33
  • Great but.. what's your *question*? As for the 'Swing' part of it, you might get some ideas from [FileBro](http://stackoverflow.com/questions/6182110). – Andrew Thompson Sep 24 '13 at 06:54
  • Andrew Thompson- i want to compare the files and folders from one directory to the files and folders of other directory.If match founds then we should delete the duplicate file.... – user5390 Sep 24 '13 at 09:11

1 Answers1

2

Consider using the strategy pattern to implement a suitable predicate for supported file types. A common approach is to define an enum in which each element implements a common interface method. The implementation might include length and type, as well as criteria unique to each file type.

public interface FileComp {
   public boolean equals(File one, File two);
}
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • trash god->can u send me one sample executable code that will compare two different files and display the result so that i can get some idea – user5390 Sep 24 '13 at 10:58
  • Although [MD5](http://stackoverflow.com/q/304268/230513) is cryptographically weak, matching checksums would _very_ likely represent identical files. – trashgod Sep 24 '13 at 14:18