Traversing a tree to a given depth without using recursion.

Write a Java console application that takes three parameters: - path to the initial directory (rootPath) - search depth - non-negative integer (depth) - mask - string (mask)

The application should find all the elements of the file system tree located at depth depth from the root of the rootPath tree, which in their name contain the string mask. Requirements: - The application must be implemented WITHOUT using recursion. - The application should not be dependent on the OS.


Assistance is needed in solving this algorithm, especially in implementing the search for the required files to a predetermined depth.

  • 3
    What is the problem? I think you should break up the question into parts, for example "how to get a list of files in the folder" "how to bypass the tree in depth without recursion" and so on. In general, the task is not difficult, so it is not clear what the problem is. On this resource, it is not customary to do tasks for someone , here they help in the decision. - pavel
  • I understand how to get the files and list the directory of the current directory, but how to get all the files in the subdirectories? - scalalaz
  • public class Catalog {public Catalog (String rootPacht, int deth, String mask) {this.rootPacht = rootPacht; this.deth = deth; this.mask = mask; } public void readCatalog () throws IOException {// define an object for the directory File dir = new File (rootPacht); // List of all directory objects File [] nameFile = dir.listFiles (); for (File nameFile1: nameFile) {if (nameFile1.isDirectory ()) {} - scalalaz
  • Then the question arises, how to realize not getting all the directory elements, but only for example up to level 3 of the file system tree nesting? - scalalaz
  • Maybe you just give a list of references where you need to dig for the implementation of this task, if it seems to you not difficult? - scalalaz

0