Created
May 20, 2015 15:54
-
-
Save danialfarid/f60a523b777cbdb5c0c8 to your computer and use it in GitHub Desktop.
remove duplicate files generated by picasa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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