public static void main(final String[] args) {
        if (args.length < 1) {
            System.err.println("Missing directory path");
            System.exit(-1);
        }
        final File topLevelDir = new File(args[0]);
        if (!topLevelDir.isDirectory() || !topLevelDir.canRead()) {
            System.err.println("Path specification is not an accessible directory " + args[0]);
            System.exit(-1);
        }

        // recursively survey file paths
        final String[] scratch = new String[256];
        final List<String[]> pathList = new ArrayList<>();
        collectPaths(topLevelDir, pathList, scratch, 0);
        pathList.sort(new PathComparator());

        // find maximum lengths of each entry
        final int[] maxLen = findMaxLengths(pathList);

        // If args.length is 1, write report to System.out,
        // otherwise, write to a file.
        if (args.length == 1) {
            surveyFiles(topLevelDir, pathList, maxLen, false, System.out);
        } else {

            boolean csv = false;

            final int i = args[1].lastIndexOf('.');
            if (i > 0) {
                final String ext = args[1].substring(i);
                if (".csv".equalsIgnoreCase(ext)) {
                    csv = true;
                }
            }
            final File reportFile = new File(args[1]);
            try (FileOutputStream fos = new FileOutputStream(reportFile);
                    BufferedOutputStream bos = new BufferedOutputStream(fos);
                    PrintStream ps = new PrintStream(bos, true, StandardCharsets.UTF_8.name())) {
                surveyFiles(topLevelDir, pathList, maxLen, csv, ps);
            } catch (final IOException ioex) {
                System.err.println("IOException writing report to " + args[1]);
                System.err.println("" + ioex.getMessage());
            }
        }
    }
@param args the command line arguments
src/test/java/org/apache/commons/imaging/examples/tiff/SurveyTiffFolder.java