Created
September 8, 2020 17:45
-
-
Save LeoPFreitas/df5f9bc896e1e5965dd87288027141f7 to your computer and use it in GitHub Desktop.
Recursively find empty directories -- need command line argument
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
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