Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data structure to store a directory structure ?

I am developing a simple java web application using struts 2 framework. the purpose of the application is to display a specific directory structure under my computer using a JSP page.

My question is which data structure to use in order to store a directory structure, so that the JSP page can access that directory structure object from the action class.

ps:I want to use the following java code to traverse the directory.

Plz help

import java.io.File;

public class DisplayDirectoryAndFile{

    public static void main (String args[]) {

        displayIt(new File("C:\\Downloads"));
    }

    public static void displayIt(File node){

        System.out.println(node.getAbsoluteFile());

        if(node.isDirectory()){
            String[] subNote = node.list();
            for(String filename : subNote){
                displayIt(new File(node, filename));
            }
        }

    }
}
like image 572
user1441218 Avatar asked Dec 07 '12 01:12

user1441218


People also ask

Which data structure is used to store the directory entries?

The inode (index node) is a data structure in a Unix-style file system that describes a file-system object such as a file or a directory. Each inode stores the attributes and disk block locations of the object's data.

What is directory structure in data structure?

In computing, a directory structure is the way an operating system arranges files that are accessible to the user. Files are typically displayed in a hierarchical tree structure.

What data structure is used for file systems?

There are two important data structures used to represent information about a virtual file system, the vfs structure and the v-node. Each virtual file system has a vfs structure in memory that describes its type, attributes, and position in the file tree hierarchy.

How do I create a directory structure diagram?

Use the Creately folder structure template, to draw a diagram to organize folders. Set up a folder for each type of document, then create subfolders for each topic under the parent folder. Place any file that does not fit into other folders, into an uncategorized folder.


1 Answers

Directory structures are very easily modeled by trees. You can think of each node representing a directory or file, with edges running from directories to the contents of that directory.

You could represent the tree itself by having a node class that stores the name of the entity (directory or file), whether or not it is a directory, and a map from the names of its subdirectories / files to the nodes for those subdirectories or files.

Hope this helps!

like image 187
templatetypedef Avatar answered Sep 30 '22 02:09

templatetypedef