public static void traverse(
      final File directory, final IDirectoryTraversalCallback callback, final boolean recurse) {
    final File[] files = directory.listFiles();

    if (files == null) {
      return;
    }

    callback.entering(directory);

    for (final File file : files) {
      if (!file.isDirectory()) {
        callback.nextFile(file);
      }
    }

    if (recurse) {
      for (final File file : files) {
        if (file.isDirectory()) {
          traverse(file, callback);
        }
      }
    }

    callback.leaving(directory);
  }
Recursively traverses through a directory.

@param directory The directory to traverse.
@param callback The callback to call for each file.
java/zylib/src/main/java/com/google/security/zynamics/zylib/io/DirUtils.java