Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2007-03-28
5
Medium Priority
?
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Author Comment

by:ericylr
ID: 18808038
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
ID: 18808068
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
ID: 18809881
So what is your question?
0
 

Author Comment

by:ericylr
ID: 18812977
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 1500 total points
ID: 18815671
"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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

610 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