// Erika Wolfe, CSE 143 // This program prints out the structure of a given directory or file import java.io.*; import java.util.*; public class DirectoryCrawler { public static void main(String[] args) { Scanner console = new Scanner(System.in); System.out.print("directory or file name? "); String name = console.nextLine(); File f = new File(name); if (!f.exists()) { System.out.println("That file or directory does not exist"); } else { print(f); } } // print the name of the file // if the file is a directory, print its children with // standard directory indentation public static void print(File file) { print(file, 0); } // print the name of the file at the given indentation level // if the file is a directory, print its children at a // higher indentation level private static void print(File file, int indent) { for (int i = 0; i < indent; i++) { System.out.print(" "); } System.out.println(file.getName()); if (file.isDirectory()) { File[] subFiles = file.listFiles(); for (File subFile : subFiles) { print(subFile, indent + 1); } } } }