Solved

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

Posted on 2007-03-28
5
196 Views
Last Modified: 2013-11-23
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
0
Comment
Question by:ericylr
  • 3
  • 2
5 Comments
 

Author Comment

by:ericylr
Comment Utility
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;
      }


 }
0
 

Author Comment

by:ericylr
Comment Utility
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?
0
 
LVL 20

Expert Comment

by:gatorvip
Comment Utility
So what is your question?
0
 

Author Comment

by:ericylr
Comment Utility
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
0
 
LVL 20

Accepted Solution

by:
gatorvip earned 500 total points
Comment Utility
"d" - you can get this via File.isDirectory()

java.io.File has the following methods (all return a boolean):       
canExecute() - Tests whether the application can execute the file denoted by this abstract pathname.
canRead() -  Tests whether the application can read the file denoted by this abstract pathname.
canWrite() - Tests whether the application can modify the file denoted by this abstract pathname.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now