Read directory structure into tree structure

Hi ya,
I want to be able to write a command line program that either takes a root node(directory root) or just takes the directory root from where the program is run reads in the directory tree into a tree structure. Then I want to analyse the tree.
I would like to know what are the best ways to do this and what are the most useful classes.
Thanks a lot for the help,
Martin

Here is a quickie du(1) (disk usage) clone that should give some hints. The Getopt class is something I wrote so you won't be able to compile this as such.
import java.io.File;
public class Du
    public static void main(String args[])
        boolean sum_mode = false;
        Getopt getopt = new Getopt(args, "sk");
        while (getopt.next()) {
            switch (getopt.option()) {
              case 's':
                  sum_mode = true;
                  break;
              case 'k':
                  break;
              default:
                  System.err.println("du: unknown option \"-" + getopt.optionName() + "\"");
                  System.exit(1);
        if (getopt.parameterCount() == 0) {
            du(new File("."), ".", sum_mode, true);
        } else {
            for (int n = 0; n < getopt.parameterCount(); n++) {
                String name = getopt.parameter(n);
                du(new File(name), name, sum_mode, true);
    private static long du(File file, String path, boolean sum_mode, boolean topmost_file)
        long bytes = 0;
        if (file.isDirectory()) {
            File files[] = file.listFiles();
            String sub_path = path + "/" + file.getName();
            for (File f : files)
                bytes += du(f, sub_path, sum_mode, false);
            if (!sum_mode || topmost_file)
                System.out.println((bytes / 1024) + "\t" + path + "/" + file.getName());
        } else {
            bytes = file.length();
            if (topmost_file)
                System.out.println((bytes / 1024) + "\t" + path + "/" + file.getName());
        return bytes;
}

Similar Messages

  • Displaying of uploaded directory in a tree structure using servlet

    I have uploaded a directory at the server side.I want to diplay the whole directory in tree form at the client side.I don't want to use Jtree or swing option neither applets.I want to do it using Java Server Page.But I am not able to do it??COuld anyone sujjest a method or can send me a piece of code that may help me to do this...Looking forward for your Brainstorming replies....and codes....

    Could you please explain it more and if possible can u give piece of code??I will be grateful to you...

  • How can i change the windows structure into mac structure

    Before i had a mac i used my iPod on a windows computer. When i connect my iPod to my mac i see that i can only repair my iPod. I can't update . It sais that only Ipods with a mac structure can be updated.
    So is there a way to change the windows structure to a mac structure?

    You cannot change a Windows iPod into a Mac iPod without restoring it, which erases its contents. To restore it, use the repair button you saw.
    (24236)

  • Reading files and converting into xml structure

    Hi,
    In my application a client requests for the folder structure information to a server through RMI. The server needs to read files and folders on local machine and convert it into some structure (I am thinking of using xml) and send it back. For eg: I am planning to have Server send back something like:
    <directory name = "parentdirectory">
    <file name = "abc.jpg"/>
    <file name = "def.bmp"/>
    <directory" name = "subdirectory">
    <file name = "hij.jpg"/>
    <file name = "klm.bmp"/>
    </directory>
    </directory>
    It is just the names of the files I am interested in and not the contents. Is this a good approach of sending back the data as a string containg xml definition. Is there any better appproach in terms of performance, memory etc? I am currently planning on using DOM for construction of this structure. Is there a source code for reading and converting the folder structure into xml. Just for your information, the clients gets this information and shows it as a tree structure on the GUI.
    Thanks!!!!

    Is this a good approach of sending back the data as a string containg xml definition. It'll work.
    An alternative, more direct approach is to build a memory representation and send this as argument/return value of an RMI call. You'd need to write classes MyDirectory and MyFile; MyFile has just a name; MyDirectory has a name and a collection of MyDirectory and one of MyFile. Make these classes implement Serializable and you can send them over RMI.
    The effort to write those trivial classes would be less than to implement XML encoding/decoding, and also in terms of runtime performance and memory it will be hard to beat Java's serialization with anything XML-based. In this case I doubt performance/memory are relevant considerations though.
    If for some reason I'd go for sending XML Strings anyway, I wouldn't do the encoding/decoding myself; I'd use XStream to convert Java classes to/from XML and still end up writing the above two classes and be done.
    Sorry if you wanted a simple yes or no :-)

  • Tree Structure in Active Directory

    Hi,
    I am trying ot come up with a design of some sort if generic LDAP connector different LDAP servers. So far I have been just testing against Active Directory and OpenLDAP.
    I know there are numerous implementations out there but the difference in features between these two itself have made the design difficult.
    I had a question in regards to the way the data is organized in Active Directory as opposed to OpenLDAP.
    In active directory you can have an
    OU
    CN {person}
    CN{group}
    Now users under different OU's can have access to other OU's I figure by belonging to the CN{group } under that OU . But the same user can't exists under two different OU's with the exact same attribute values. Is my understanding right??
    Now when I used this OpenLDAP Windows version I could very easily create the same user under two different OU's.
    Further on in Active Directory you have something called the objectGUID to get to the entry even if it is moved around in the tree casue at one point it can exists in only one place. Is this understanding right??
    What happens in case of an OpenLDAP how do we get the unique id?
    Please help

    tigerkumar wrote:
    HI
    I am using swing on that JPanel
    and
    i got the drives of system in my combo box
    can u tell me how to show selected drive`s folders in a tree structure
    using JTree
    how i can show the the directories(folder`s) of a drive into the JTree box
    directory to be selected from ComboBox showing driveswhat is wrong with you?
    why keep on multi-posting, I give you a solution and you ignore it.
    http://forum.java.sun.com/thread.jspa?threadID=5217925&tstart=0
    no one will help you if you keep on doing that.

  • Tree structure of system directory

    HI
    I am using swing on that JPanel
    and
    i got the drives of system in my combo box
    can u tell me how to show selected drive`s folders in a tree structure
    using JTree
    how i can show the the directories(folder`s) of a drive into the JTree box
    directory to be selected from ComboBox showing drives

    tigerkumar wrote:
    ok
    sorry for that
    i will take care of that
    Please help me in this problemI have given you an answer in the swing forum and you keep on
    multi-posting and ignoring the people who help you.
    read the solution here.
    http://forum.java.sun.com/thread.jspa?threadID=5217925&tstart=0
    I think this is the 4th time you keep on posting the same problem.
    next time there would be no help.

  • Import already existing directory structure into DFS namespace?

    Hi all,
    I'm planning to migrate three file servers to a single DFS namespace and after reading the official docs and numerous blog posts I'm still unsure about the right way to do it.
    The "main" server already has a share with a complex directory structure, called \\server1\team, and that share shall become the root of the new DFS namespace, lets call it  \\domain.local\team.
    Part of that already existing directory structure is this folder: \\server1\team\admin\communication\archive. The folder "archive" contains thousands of files in numerous folders and shall become a dfs link to another share \\server2\archive. But
    before I can create the folder "archive" as a dfs link I have to create the folder "admin" in the dfs hierarchy of course, then below that the folder "communication"
    Question: When I try to create a folder "admin" in the dfs namespace, I get the error message "the folder cannot be created in the namespace. The file exists."
    Ok, the folder "admin" indeed exists, but how can I "import" this branch of the existing directory hierarchy into the dfs namespace?
    Do I have to rename the existing folder "admin" to e.g. "admin2", then create the dfs folder "admin" and move the complete directory structure below "admin2" to "admin"? Or can I simply make the existing folder
    "admin" a dfs folder?
    Thanks in advance!
    Regards
    Christoph

    Mandy, thanks for your feedback!
    I have to describe my problem more precisely: creating the root of the new DFS namespace is *not* the problem. This worked for me exactly as you expained it. The problem appears when I try to create a folder below that root in the DFS namespace. If that
    folder already exists in the share you cannot choose how to handle security settings but you get an error message, and that's it.
    This may be helpfull to explain what I want to achieve:
    Old structure:
    \\server1\team - folder admin - subfolder "archive" - lots of subfolders and files
    Now I want to move all files and folders from "archive" to \\server2\archive and link this share into the new DFS namespace, so that our users don't notice any change when they access that archive folder.
    new structure:
    1. Create DFS namespace root: \\domain.local\team  -> \\server1\team   (works!)
                |
    2. Create folder admin  (problem!)
                |
    3. Create subfolder "archive" -> \\server2\archive (not possible becaues "admin" couldn't be created)
    I could perhaps create a DFS namespace with the root \\server1\team\admin\archive and link that to \\server2\archive, but I would like to avoid creating a new namespace for each share which from \\server2 which I mount into some subfolder of \\server1\team...
    Thanks for reading.
    Regards
    Christoph

  • How do I read text from specific rows and columns in a tree structure?

    How do I read text from specific rows and columns in a tree structure? In a table you can specify the cell to read from but I have not been able to figure out how to do this with a tree structure.

    You need to set two properties to activate the correct cell and then you can read it's string property.
    The positioning properties are the "ActiveItemTag" and
    "ActiveColNum" properties. With them you select the tree item by it's tag and the active column. The string can then be read from the "Cell String" property.
    MTO

  • The tree structure in SE09

    Hello Gurus,
            will you please explain the tree item of the tree structure in all level in SE09 ?
    Many thanks,
    Frank Zhang

    Hi,
    The Transport Organizer with Transaction SE09 or SE10. You can also access the request overview of the Transport Organizer from all ABAP Workbench transactions by choosing Environment Transport Organizer (Requests).
    The Display function lets you search for all requests that belong to the specified user and match the standard selection criteria set. You can change the standard selection as required.
    The status selection for requests is used by default for the task selection. However, you can change this by going to the initial screen and choosing Settings other settings.
    Tasks that are not assigned to a request can no longer be created. This means that these tasks are no longer displayed as standard. If you still own tasks of this type, use the request search to display them
    Piece lists
    You can use this request type to set up your own object lists and save them under a name of your choice.
    Piece lists have the following attributes:
    u2022You cannot release them this also means that you cannot transport them.
    u2022They have an object directory entry and are therefore assigned to a package.
       They have the same transport attributes as all objects in this package.
    u2022If you have assigned the piece list to a transportable package, then when you make changes to the piece list the entry LIMU COMM <piece list name> is made in your current change request.
    u2022After the change request has been imported, the piece list is also in the target system of the request; however, the objects entered in the piece list are not automatically included in the transport.
    Delivery Transports
    Use the Delivery selection screen to display transports that deliver software changes from SAP or SAP partners to customers.
    The selection screen covers the following request types:
    u2022Piece list for upgrade
    This transport type imports new releases into your SAP System when you upgrade.
    u2022Piece list for Support Package
    This transport type imports corrections into your SAP System.

  • Loading in tree structure from arraylist

    Hi,
    I have a ArrayList contains xml file path like
    ArrayList al={"/folder1/sub1/sub11/1.xml",
    "/folder1/sub1/2.xml,
    "/folder1/test1/3.xml",
    "/folder2/sub2/4.xml",
    "/folder2/sub2/sub3/5.xml"}
    Note: 1.This arraylist objects are dynamically loaded.
    2.The objects in array list are not file system directory path like (e.g., C:/folder1/sub1/.....). Its string added in arraylist.
    using this arraylist i want to load it in jsp tree structure, like
    folder1
    |___sub1
    | |_sub11
    | | |__1.xml
    | |_2.xml
    |___test1
    |_3.xml
    folder2
    |
    |_sub2
    |___4.xml
    |___sub3
    |___5.xml
    Can any one help me with logic or predefined function in java to iterate each string array object and split parent and sub child folder and load it in tree.
    Edited by: manjunath_2284 on Aug 11, 2009 6:04 AM

    Create a Node class that has a name and Map<String, Node> as children.
    Iterate over the list, split each entry on "/", and place the parts that you get into the Node structure.

  • How to get Text for nodes in Tree Structure

    Hi Friends,
    How to get Text for nodes in Tree Structure
    REPORT  YFIIN_REP_TREE_STRUCTURE  no standard page heading.
                       I N I T I A L I Z A T I O N
    INITIALIZATION.
    AUTHORITY-CHECK OBJECT 'ZPRCHK_NEW' :
                      ID 'YFIINICD' FIELD SY-TCODE.
      IF SY-SUBRC NE 0.
        MESSAGE I000(yFI02) with SY-TCODE .
        LEAVE PROGRAM.
      ENDIF.
    class screen_init definition create private.
    Public section
      public section.
        class-methods init_screen.
        methods constructor.
    Private section
      private section.
        data: container1 type ref to cl_gui_custom_container,
              container2 type ref to cl_gui_custom_container,
              tree type ref to cl_gui_simple_tree.
        methods: fill_tree.
    endclass.
    Class for Handling Events
    class screen_handler definition.
    Public section
      public section.
        methods: constructor importing container
                   type ref to cl_gui_custom_container,
                 handle_node_double_click
                   for event node_double_click
                   of cl_gui_simple_tree
                   importing node_key .
    Private section
      private section.
    endclass.
    *&                        Classes implementation
    class screen_init implementation.
    *&                        Method INIT_SCREEN
      method init_screen.
        data screen type ref to screen_init.
        create object screen.
      endmethod.
    *&                        Method CONSTRUCTOR
      method constructor.
        data: events type cntl_simple_events,
              event like line of events,
              event_handler type ref to screen_handler.
        create object: container1 exporting container_name = 'CUSTOM_1',
                       tree exporting parent = container1
                         node_selection_mode =
                cl_gui_simple_tree=>node_sel_mode_multiple.
        create object: container2 exporting container_name = 'CUSTOM_2',
        event_handler exporting container = container2.
    event-eventid = cl_gui_simple_tree=>eventid_node_double_click.
        event-appl_event = ' '.   "system event, does not trigger PAI
        append event to events.
        call method tree->set_registered_events
             exporting events = events.
        set handler event_handler->handle_node_double_click for tree.
         call method: me->fill_tree.
      endmethod.
    *&                        Method FILL_TREE
      method fill_tree.
        data: node_table type table of abdemonode,
              node type abdemonode.
    types:    begin of tree_node,
              folder(50) type c,
              tcode(60) type c,
              tcode1(60) type c,
              tcode2(60) type c,
              text(60) type c,
              text1(60) type c,
              text2(60) type c,
              end of tree_node.
      data:  wa_tree_node type tree_node,
                t_tree_node type table of tree_node.
    wa_tree_node-folder = text-001.
    wa_tree_node-tcode  = text-002.
    wa_tree_node-text =  'Creditors ageing'.
    wa_tree_node-tcode1 = text-003.
    wa_tree_node-text1 =  'GR/IR aging'.
    wa_tree_node-tcode2 = text-004.
    wa_tree_node-text2 =  'Bank Balance'.
    append wa_tree_node to t_tree_node.
    clear wa_tree_node .
    wa_tree_node-folder = text-005.
    wa_tree_node-tcode  = text-006.
    wa_tree_node-text =  'Creditors ageing'.
    wa_tree_node-tcode1 = text-007.
    wa_tree_node-text1 =  'Creditors ageing'.
    wa_tree_node-tcode2 = text-008.
    wa_tree_node-text2 =  'Creditors ageing'.
    append wa_tree_node to t_tree_node.
    clear wa_tree_node .
    wa_tree_node-folder = text-009.
    wa_tree_node-tcode  = text-010.
    wa_tree_node-text =  'Creditors ageing'.
    wa_tree_node-tcode1 = text-011.
    wa_tree_node-text1 =  'Creditors ageing'.
    wa_tree_node-tcode2 = text-012.
    wa_tree_node-text2 =  'Creditors ageing'.
    append wa_tree_node to t_tree_node.
    clear wa_tree_node .
    node-hidden = ' '.                 " All nodes are visible,
        node-disabled = ' '.               " selectable,
        node-isfolder = 'X'.                                    " a folder,
        node-expander = ' '.               " have no '+' sign forexpansion.
        loop at t_tree_node into wa_tree_node.
          at new folder.
            node-isfolder = 'X'.                      " a folder,
            node-node_key = wa_tree_node-folder.
                   clear node-relatkey.
            clear node-relatship.
            node-text = wa_tree_node-folder.
            node-n_image =   ' '.
            node-exp_image = ' '.
            append node to node_table.
          endat.
         at new tcode .
            node-isfolder = ' '.                          " a folder,
            node-n_image =   '@CS@'.       "AV is the internal code
            node-exp_image = '@CS@'.       "for an airplane icon
            node-node_key = wa_tree_node-tcode.
             node-text = wa_tree_node-text .
                     node-relatkey = wa_tree_node-folder.
            node-relatship = cl_gui_simple_tree=>relat_last_child.
          endat.
          append node to node_table.
        at new tcode1 .
            node-isfolder = ' '.                          " a folder,
            node-n_image =   '@CS@'.       "AV is the internal code
            node-exp_image = '@CS@'.       "for an airplane icon
            node-node_key = wa_tree_node-tcode1.
                     node-relatkey = wa_tree_node-folder.
            node-relatship = cl_gui_simple_tree=>relat_last_child.
              node-text = wa_tree_node-text1.
         endat.
          append node to node_table.
           at new tcode2 .
            node-isfolder = ' '.                          " a folder,
            node-n_image =   '@CS@'.       "AV is the internal code
            node-exp_image = '@CS@'.       "for an airplane icon
            node-node_key = wa_tree_node-tcode2.
                     node-relatkey = wa_tree_node-folder.
            node-relatship = cl_gui_simple_tree=>relat_last_child.
            node-text = wa_tree_node-text2.
         endat.
          append node to node_table.
        endloop.
        call method tree->add_nodes
             exporting table_structure_name = 'ABDEMONODE'
                       node_table = node_table.
      endmethod.
    endclass.
    *&                        Class implementation
    class screen_handler implementation.
    *&                        Method CONSTRUCTOR
      method constructor.
       create object: HTML_VIEWER exporting PARENT = CONTAINER,
                      LIST_VIEWER exporting I_PARENT = CONTAINER.
      endmethod.
    *&                 Method HANDLE_NODE_DOUBLE_CLICK
      method handle_node_double_click.
      case node_key(12).
    when 'Creditors'.
    submit YFIIN_REP_CREADITORS_AGING  via selection-screen and return.
    when  'Vendor'.
    submit YFIIN_REP_VENDOR_OUTSTANDING  via selection-screen and return.
    when 'Customer'.
    submit YFIIN_REP_CUSTOMER_OUTSTANDING  via selection-screen and
    return.
    when 'GR/IR'.
    submit YFIIN_REP_GRIR_AGING  via selection-screen and return.
    when 'Acc_Doc_List'.
    submit YFIIN_REP_ACCOUNTINGDOCLIST  via selection-screen and return.
    when 'Bank Bal'.
    submit YFIIN_REP_BANKBALANCE  via selection-screen and return.
    when 'Ven_Cus_Dtl'.
    submit YFIIN_REP_VENDORCUST_DETAIL via selection-screen and return.
    when 'G/L_Open_Bal'.
    submit YFIIN_REP_OPENINGBALANCE via selection-screen and return.
    when 'Usr_Authn'.
    submit YFIIN_REP_USERAUTHRIZATION via selection-screen and return.
    endcase.
      endmethod.
    endclass.
    Program execution ************************************************
    load-of-program.
      call screen 9001.
    at selection-screen.
    Dialog Modules PBO
    *&      Module  STATUS_9001  OUTPUT
          text
    module status_9001 output.
      set pf-status 'SCREEN_9001'.
      set titlebar 'TIT_9001'.
      call method screen_init=>init_screen.
    endmodule.                 " STATUS_9001  OUTPUT
    Dialog Modules PAI
    *&      Module  USER_COMMAND_9001  INPUT
          text
    module user_command_9001 input.
    endmodule.                 " USER_COMMAND_9001  INPUT
    *&      Module  exit_9001  INPUT
          text
    module exit_9001 input.
    case sy-ucomm.
    when 'EXIT'.
      set screen 0.
    endcase.
    endmodule.
            exit_9001  INPUT

    you can read  the table node_table with nody key value which imports when docubble click the the tree node (Double clifk event).
    Regards,
    Gopi .
    Reward points if helpfull.

  • How to get the folder name of selected subitem in tree structure?

    Hi All,
               I created a tree structure like below.
             ->Folder1-- 1
                              2
                              3
            ->Folder2-----1
                               2
                               3
                    i.e i have two folders & each folder having the values like above.Now i want to perform some action by clicking on the any of the values.Suppose if i click value 2,i want to do some action.the actions need to perform is varies from floder to to folder.
            So How can i get the folder name of clicked Value?
    Regards,
    Ravi

    Hi Kumar ,
    the below code should help you.
    Register the below action for the leaf node for which u need the subfolder's name above it.
    Worked fine in my system ...hope it does in ur scenario too
    method ONACTIONGET_PATH .
      data : lr_element TYPE REF TO if_wd_context_element,
             lr_node TYPE REF TO if_wd_context_node,
             ls_path type string,
             ls_path_node TYPE string,
             lt_string type TABLE OF string,
             l_lines type i,
             l_lines_1 TYPE i.
      lr_element = wdevent->get_context_element( 'CONTEXT_ELEMENT' ).
    **-> getting the path of the node/leaf
    *which  u had clicked and from that getting the node above it
      ls_path = lr_element->get_path( ).
      SPLIT ls_path at '.' into table lt_string.
    -> remove the first 2 entries as they will contain the view name
      DELETE lt_string FROM 1 to 2.
      l_lines = LINES( lt_String ).
      l_lines_1 = l_lines - 1.
    -> remove the last 2 entries as they will contain the element in the path
      DELETE lt_string  from l_lines_1 to l_lines.
      LOOP AT lt_string into ls_path.
        CONCATENATE LINES OF LT_STRING into ls_path_node SEPARATED BY '.'.
      ENDLOOP.
    **-> getting access to the node above the leaf element
    LR_NODE = WD_CONTEXT->PATH_GET_NODE( path = ls_path_node ).
    lr_element = lr_node->get_element( ).
    **-> Getting the name of the folder...
    *here path is the attribute in my context which stores the name of the folder
    lr_element->get_attribute( EXPORTING name = 'PATH' IMPORTING value = ls_path ).
    endmethod.

  • Listing File Hierarchy in console using a Tree structure

    first off i'm a college student. i'm not that good at java... we got this CA in class and try as i might i just can't get my head around it
    i was wondering if someone who know a bit more about java then i do would point me in the right direction, were i'm going wrong in my code
    i have to list out sub-files and sub-directorys of a folder (i.e. C:/test) to console using tree structure
    like this
    startingdir
    dir1 //subfolder of startingdir
    dir11 //subfolder of dir1
    dir111 //subfolder of dir11
    dir12 //subfolder of dir1
    file1A // document on dir1
    dir2 //subfolder of startingdir
    Tree.java
    import java.util.Iterator;
    import java.util.LinkedList;
    import java.util.ListIterator;
    import java.util.NoSuchElementException;
    import java.util.Deque;
    public class Tree<E> {
        // Each Tree object is an unordered tree whose
        // elements are arbitrary objects of type E.
        // This tree is represented by a reference to its root node (root), which
        // is null if the tree is empty. Each tree node contains a link to its
        // parent and a LinkedList of child nodes
        private Node root;
        //////////// Constructor ////////////
        public Tree () {
        // Construct a tree, initially empty.
            root = null;
        //////////// Accessors ////////////
        public boolean isEmpty () {
        // Return true is and only if this tree is empty.
             return (root == null);
        public Node root () {
        // Return the root node of this tree, or null if this tree is empty.
            return root;
        public Node parent (Node node) {
        // Return the parent of node in this tree, or null if node is the root node.
            return node.parent;
        public void makeRoot (E elem) {
        // Make this tree consist of just a root node containing element elem.
            root = new Node(elem);
        public Node addChild (Node node, E elem) {
        // Add a new node containing element elem as a child of node in this
        // tree. The new node has no children of its own. Return the node
        // just added.
            Node newChild = new Node(elem);
            newChild.parent = node;
            node.children.addLast(newChild);
            return newChild;
        public E element (Node node) {
             return node.getElement();
        //////////// Iterators ////////////
        public Iterator childrenIterator (Node node) {
            return node.children.iterator();
        public Iterator nodesPreOrder () {
        // Return an iterator that visits all nodes of this tree, with a pre-order
        // traversal.
            return new Tree.PreOrderIterator();
        //////////// Inner classes ////////////
        public class Node {
            // Each Tree.Node object is a  node of an
            // unordered tree, and contains a single element.
            // This tree node consists of an element (element),
            // a link to its parent
            // and a LinkedList of its children
            private E element;
            private Node parent;
            private LinkedList<Node> children;
            private Node (E elem) {
                // Construct a tree node, containing element elem, that has no
                // children and no parent.
                this.element = elem;
                this.parent = null;
                children = new LinkedList<Node>();
            public E getElement () {
            // Return the element contained in this node.
                return this.element;
            public String toString () {
            // Convert this tree node and all its children to a string.
                String children = "";
                // write code here to add all children
                return element.toString() + children;
            public void setElement (E elem) {
            // Change the element contained in this node to be elem.
                this.element = elem;
        public class PreOrderIterator implements Iterator {
            private Deque<Node> track; //Java recommends using Deque rather
            // than Stack. This is used to store sequence of nomempty subtrees still
            //to be visited
            private PreOrderIterator () {
                track = new LinkedList();
                if (root != null)
                    track.addFirst(root);
            public boolean hasNext () {
                return (! track.isEmpty());
            public E next () {
                Node place = track.removeFirst();
                //stack the children in reverse order
                if (!place.children.isEmpty()) {
                    int size = place.children.size(); //number of children
                    ListIterator<Node> lIter =
                            place.children.listIterator(size); //start iterator at last child
                    while (lIter.hasPrevious()) {
                        Node element = lIter.previous();
                        track.addFirst(element);
                return place.element;
            public void remove () {
                throw new UnsupportedOperationException();
        FileHierarchy.java
    import java.io.File;
    import java.util.Iterator;
    public class FileHierarchy {
        // Each FileHierarchy object describes a hierarchical collection of
        // documents and folders, in which a folder may contain any number of
        // documents and other folders. Within a given folder, all documents and
        // folders have different names.
        // This file hierarchy is represented by a tree, fileTree, whose elements
        // are Descriptor objects.
        private Tree fileTree;
        //////////// Constructor ////////////
        public FileHierarchy (String startingDir, int level) {
            // Construct a file hierarchy with level levels, starting at
            // startingDir
            // Can initially ignore level and construct as many levels as exist
            fileTree = new Tree();
            Descriptor descr = new Descriptor(startingDir, true);
            fileTree.makeRoot(descr);
            int currentLevel = 0;
            int maxLevel = level;
            addSubDirs(fileTree.root(), currentLevel, maxLevel);
        //////////// File hierarchy operations ////////////
        private void addSubDirs(Tree.Node currentNode, int currentLevel,
                int maxLevel) {
        // get name of directory in currentNode
        // then find its subdirectories (can add files later)
        // for each subdirectory:
        //    add it to children of currentNode - call addChild method of Tree
        //    call this method recursively on each child node representing a subdir
        // can initially ignore currentLevel and maxLevel   
            Descriptor descr = (Descriptor) currentNode.getElement();
            File f = new File(descr.name);
            File[] list = f.listFiles();
            for (int i = 0; i < list.length; ++i) {
                if (list.isDirectory()) {
    File[] listx = null;
    fileTree.addChild(currentNode, i);
    if (list[i].list().length != 0) {
    listx = list[1].listFiles();
    addSubDirs(currentNode,i,1);
    } else if (list[i].isFile()) {
    fileTree.addChild(currentNode, i);
    // The following code is sample code to illustrate how File class is
    // used to get a list of subdirectories from a starting directory
    // list now contains subdirs and files
    // contained in dir descr.name
    ////////// Inner class for document/folder descriptors. //////////
    private static class Descriptor {
    // Each Descriptor object describes a document or folder.
    private String name;
    private boolean isFolder;
    private Descriptor (String name, boolean isFolder) {
    this.name = name;
    this.isFolder = isFolder;
    FileHierarchyTest.javapublic class FileHierarchyTest {
    private static Tree fileTree;
    public static void main(String[] args) {
    FileHierarchy test = new FileHierarchy ("//test", 1);
    System.out.println(test.toString());

    Denis,
    Do you have [red hair|http://www.dennisthemenace.com/]? ;-)
    My advise with the tree structure is pretty short and sweet... make each node remember
    1. it's parent
    2. it's children
    That's how the file system (inode) actually works.
    <quote>
    The exact reasoning for designating these as "i" nodes is unsure. When asked, Unix pioneer Dennis Ritchie replied:[citation needed]
    In truth, I don't know either. It was just a term that we started to use. "Index" is my best guess, because of the
    slightly unusual file system structure that stored the access information of files as a flat array on the disk, with all
    the hierarchical directory information living aside from this. Thus the i-number is an index in this array, the
    i-node is the selected element of the array. (The "i-" notation was used in the 1st edition manual; its hyphen
    became gradually dropped).</quote>

  • Bookmark tree structure using Microsoft word 2007 not creating properly

    I have a word document file in MS office 2007. When i am converting the word document to a PDF file using the HEADING option , the bookmarks tree structure  in the PDF file is not created properly. Means that the between content of a topic is also read
    as a bookmark heading while conversion. Only the heading of a topic should be read as a bookmark and the sub heading as a sub-bookmark but the content should not come in the tree structure of bookmarks in a PDF file..
    For Example:- if MICROSOFT is the heading of any xyz.doc then it should be the parent bookmark. . but in my case , MICROSOFT is coming as a bookmark but the content inside this is also created as a bookmark..
    So my question is that what is the internal structure of the of the MS word 2007 to convert a doc to a PDF file???
    Because it is not creating the bookmarks tree structure properly...and taking the content randomly from the middle of a topic and adding it in the bookmark tree structure...(which should not happen). The font throughout the doc is the same and aligned properly..so
    why it is randomly taking the between text as a bookmark...???
    what is the root cause of this bug..?? how can this problem be solved..?? is there any sort of change have to be done in my word doc.?
    i need an urgent help regarding this...
    NOTE:- I am using MS office 2007.

    I tried this but didnt work for mr. Can you help? How did you PDFed??
    It works for me in Word 2010 (or later) using Save As PDF. It did not work in Word 2007 using the Adobe Acrobat PDF printer nor using Word 2007's save as pdf utility. (The hyperlink showed up but was not active.) It did work using the Acrobat tab in Word
    2007 (this requires Adobe Acrobat).
    I did this by:
    first creating the text box with the hyperlink in the body of the document and moving it into the footer area (but still not in the footer itself).
    Then I used the Format tab of Text Box Tools and the Postion button (More Layout Options).
    I gave it an absolute vertical position relative to the page.
    Then I cut the text box, went into the footer, and pasted it there.
    It might have worked to just create the text box in the footer itself.
    I personally prefer it that the header and footer are not part of the active page when I am typing. This hyperlink is not clickable in Word without going into the header/footer view and I'm fine with that. The QAT workaround is just fine.
    Charles Kenyon Madison, WI

  • Unable to create tree structure in Address Book like "Mail"

    I'm moving from a Windows PC environment having used both Mozilla's Thunderbird (email) & Firefox (browser) successfully for years.  Problem I'm encountering is setting up a similar structure in both Address Book & Mail!!  I set my Mail structure as follows:
    Leon Contacts
    0800 Class
    1100 Class
    T'ai Chi
    Earthquake E-tree
    Branch 1
    Branch 2
    Branch 3
    Branch 4
    From my Apple phone conversations & One-On-One sessions, this is impossible.  All Groups in Address Book are sorted in alphabetical order.  There are NO sub-groups!  When I'm composing a Mail for Mailbox, Leon Contacts, it's not easy to locate 1100 Class.  It seems  as though this logical approach to a tree structure would be useful for the community.
    I'm at a loss for getting the mail addesses easily into Mail.  Any interrim suggestions.

    Firefox doesn't do email, it's strictly a web browser.
    If you are using Firefox to access your mail, you are using "web-mail". You need to seek support from your service provider or a forum for that service.
    If your problem is with Mozilla Thunderbird, let us know and we can move this thread to the Thunderbird queue. This question currently is in the Firefox queue for answers.

Maybe you are looking for