Skip to content

Instantly share code, notes, and snippets.

@LeoPFreitas
Created September 8, 2020 17:45
Show Gist options
  • Save LeoPFreitas/df5f9bc896e1e5965dd87288027141f7 to your computer and use it in GitHub Desktop.
Save LeoPFreitas/df5f9bc896e1e5965dd87288027141f7 to your computer and use it in GitHub Desktop.
Recursively find empty directories -- need command line argument
import java.io.File;
import java.util.Scanner;
class FindEmptyDirectories {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
File file = new File(args[0]);
goRecursive(file);
sc.close();
}
public static void goRecursive(File file) {
if (file.isDirectory() && file.list().length == 0) {
System.out.print(file.getName() + " ");
return;
} else if (file.isFile()) {
return;
} else {
for (File subFile : file.listFiles()) {
goRecursive(subFile);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment