www.webdeveloper.com
Results 1 to 2 of 2

Thread: Create object of Linux file system

  1. #1
    Join Date
    Dec 2005
    Posts
    264

    Create object of Linux file system

    I would like to create an object which mirrors a Linux file system. Doesn't need to be very complicated, doesn't need file permissions, etc, but just lists the files with KB size and directors under each directory. I then will want to be able to add/delete/rename files and directories in the object.

    I was thinking of something like that listed below. Problem with this approach is it doesn't prevent duplicate file names or directory names under a given directory (really not a huge deal). Also, it is somewhat convoluted to select a given directory (some sort of loop through each directory to see if a sub-directory exists, and then inspect that directory).

    So, then I thought maybe I should make each folder a property so that duplicates are not possible and selecting a directory is as easy as folder1.dir2.dir22. Problem is one cannot create a directory called "files" as it will conflict with the files array.

    Hopefully, what I am attempting to communicate makes sense! Any suggestions on how best to proceed?

    Thanks


    Code:
    var folders={
        name:'/',
        folders:[
            {
                name:'dir1/',
                folders:[],
                files:[{name:'file11',size:20},{name:'file12',size:20}]
            },
            {
                name:'dir2/',
                folders:[
                {
                    name:'/dir22',
                    folders:[],
                    files:[{name:'file221',size:20},{name:'file222',size:20}]
                }],
                files:[{name:'file21',size:20}]
            }
        ],
        files:[{name:'file1',size:20},{name:'file2',size:20}]
    };

  2. #2
    Join Date
    Mar 2009
    Posts
    481
    What commands is it supposed to obey? "cd" and "ls" I assume, but what else? "mkdir" or "rmdir"? "mv"? And how is it to be populated to begin with? Your described object is probably sufficient to do what you want it to do as a data structure, the essential problem is writing methods/functions for the mother object.

    I would also include two other objects as a property of the main object in which the properties would consist (A first object) KEY directory name--VALUE parent directory name and (B) KEY directory name --VALUE reference to the object which has that directory name.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles