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
Solved

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

Posted on 2007-03-28
5
201 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
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 500 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
jar file executable 12 58
maven module vs maven project 3 46
jboss 7.1 start up error 1 33
Eclipse Java import and method not resolved 4 48
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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 learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

840 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