Link to home
Start Free TrialLog in
Avatar of ericylr
ericylr

asked on

Display the directory and files status, the read and write permissions

I've write a class DirectoryTour to perform an Euler Tour of a given File. it will call the methods beforeFirst, afterLast and inBetween. the method beforeFirst should be called the first time the node is vistited, the method afterLast should be called the last time the node is vistited, the method inBetween should be called in between each pair of children.

the a root of a directory like this:
c:\test0                        ------folder
c:\test0\one                -------folder
c:\test0\one\one-a      -------file
c:\test0\one\one-b      -------file
c:\test0\three               -------folder
c:\test0\two             -------folder
c:\test0\two\two-a      -------file
c:\test0\two\two-b      -------file
Avatar of ericylr
ericylr

ASKER

my DirectoryTour class is as below:

import java.io.File;


public class DirectoryTour

{


/*
 * traverse method
 * traverse all the nodes from left to right
 * when visit file at first time , make a call on the beforeFirst() method
 * when visit file at second time and still has more children for the same parent node
 * , make a call on the inBetween() method otherwise, make a call on the afterLast() method
 * when visit file at third time , make a call on the afterLast() method  
*/

      public Object traverse (File f, Object info) {

            info = beforeFirst(f, info);

            String[] fArray = new String[5];

            fArray=f.list();

            if (fArray!=null) {

                  for (int i=0; i<fArray.length; i++) {      

                        File fLeft = new File(f.getAbsolutePath() + "\\" + fArray[i]);

                        info = traverse(fLeft, info);

                        if (i<fArray.length-1) {

                              info = inBetween(f, info);
                        }

                  }
            }

            info = afterLast(f, info);

            return null;

      }



/*
 * beforeFirst method
 * print "beforeFirst:" + File name and return null
*/
      public Object beforeFirst (File f, Object info) {
               System.out.println("beforeFirst: " + f.getName());
               return null;
      }



/*
 * inBetween method
 * print "inBetween:" + File name and return null
*/

      public Object inBetween (File f, Object info) {
               System.out.println("inBetween: " + f.getName());
               return null;
      }



/*
 * afterLast method
 * print "afetrLast:" + File name and return null
*/
      public Object afterLast (File f, Object info) {
               System.out.println("afterLast: " + f.getName());
               return null;
      }


 }
Avatar of ericylr

ASKER

Now, i need write a class IndentedList which inherits from DirectoryTour and modifies the methods beforeFirst,
afterLast and inBetween so that you produce an indented list of the directory where each file name is preceded
by a number of spaces which is twice the depth in the directory structure, and where the file name is followed
by a space and the directory status, the read and write permissions in parentheses.

the output might be:
test0 (drw)
    one (drw)
        one-a (-rw)
        one-b (--w)
    three (dr-)
         three-a (-rw)
         two (drw)

any idea?
So what is your question?
Avatar of ericylr

ASKER

I've write a DirectoryTour class, now i need write a class IndentedList which inherits from DirectoryTour, and modifies the methods beforeFirst, afterLast and inBetween to displaythe directory status, the read and write permissions in parentheses.
the output might be:
test0 (drw)
    one (drw)
        one-a (-rw)
        one-b (--w)
    three (dr-)
         three-a (-rw)
         two (drw)

i do not know how to displaythe directory status, the read and write permissions, thanks
ASKER CERTIFIED SOLUTION
Avatar of gatorvip
gatorvip
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial