Browse Prior Art Database

Using Java to Avoid Recursion in Processing an AIX File Tree

IP.com Disclosure Number: IPCOM000118937D
Original Publication Date: 1997-Sep-01
Included in the Prior Art Database: 2005-Apr-01
Document File: 2 page(s) / 37K

Publishing Venue

IBM

Related People

Shue, DY: AUTHOR

Abstract

Some programs need to traverse a file tree. Starting at the home directory, for example, a list of files might reveal both files and sub-directories. As the list is processed and a sub-directory is encountered, some schemes use recursion, i.e., save the current context, change to the sub-directory, and begin processing it. As further sub-directories are encountered, more recursion occurs. Finally, the entire process must be gradually unwound until returned to the home directory. This recursive programming can be tricky.

This text was extracted from an ASCII text file.
This is the abbreviated version, containing approximately 77% of the total text.

Using Java to Avoid Recursion in Processing an AIX File Tree

      Some programs need to traverse a file tree.  Starting at the
home directory, for example, a list of files might reveal both files
and sub-directories.  As the list is processed and a sub-directory is
encountered, some schemes use recursion, i.e., save the current
context, change to the sub-directory, and begin processing it.  As
further sub-directories are encountered, more recursion occurs.
Finally, the entire process must be gradually unwound until returned
to the home directory.  This recursive programming can be tricky.

      If files must be processed in the order in which they
encountered, then there is likely no substitute for recursion.
However, when order dependency is not an issue then Java provides a
straightforward mechanism that does not take many lines of code, is
simple and written in a language which is purported to be platform
independent.  Using a Java stack simplifies the task of running a
file tree.
  1.  Instantiate a stack via "new Stack()".
  2.  Use the file list() method to provide an array of strings
       describing the directory contents.  Cycle through the array
       using the file is Directory() method.  If true, then the
       file is a directory and a synchronized stack push() method
       is used to place the name of the sub-directory onto the
       stack for later processing.  Non-directories can be handled
      ...