Skip to content

Instantly share code, notes, and snippets.

@danialfarid
Created May 20, 2015 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danialfarid/f60a523b777cbdb5c0c8 to your computer and use it in GitHub Desktop.
Save danialfarid/f60a523b777cbdb5c0c8 to your computer and use it in GitHub Desktop.
remove duplicate files generated by picasa
public static void main(String... args) {
File[] files = new File("/Users/dan/Pictures/").listFiles();
showFiles(files);
}
public static void showFiles(File[] files) {
Map<String, File> names = new HashMap<>();
for (File file : files) {
if (file.isDirectory()) {
System.out.println("Directory: " + file.getName());
showFiles(file.listFiles()); // Calls same method again.
} else {
if (names.containsKey(file.getName().replace(" 1.", "."))) {
System.out.println("duplicate File: " + file.getName() + " " + names.get(file.getName().replace(" 1.", ".")));
names.get(file.getName().replace(" 1.", ".")).delete();
}
names.put(file.getName().replace(" 1.", "."), file);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment