?
Solved

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

Posted on 2007-03-28
5
Medium Priority
?
206 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month12 days, 22 hours left to enroll

777 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