-1

So here is my scenario -- I am collecting a dynamic folder structure with javascript for a photoshop plugin I am developing. Here is what the folders may look like:

Folder 1
    subFolder1
        file1
        file2
    subFolder2
        subsubfolder1
        subsubfolder2
           file1
           file2


 Folder 2
        subFolder1
            file1
            file2
        subFolder2
            subsubfolder1
            subsubfolder2
               file1
               file2

What would this syntax look like? tried to come up with it, but doesn't look right to me. Also how would you loop through something like that? Do you for look on every sub array?

var multiArray = [ [Folder1, [subFolder1, [file1,file2],subFolder2, [subsubFolder1, subsubFolder2, [file1,file2] ], Folder2, [subFolder1, [file1,file2], subFolder2, [subsubfolder1,subsubfoler2, [file1,file2]

1 Answer 1

4
var who = {
   just: "an object",
   with: "a couple of properties"
};

var ArrayOofArrays = [
    [1,2,3],
    [4,5,7],
    [1,{},""],
    ["a",2,{c: "b",e: who}]
];

In your example:

var folder = {
    subfolders: [
        subfolder,
        subfolder
    ],
    files: [
        file,
        file
    ]
};

subfolder would be ->

var subfolder = function () {
    return {
        folders: [
        ],
        files: [
        ],
        path: "path/to/folder" // etc..
    }
};

file would be ->

var fileInfo = function () {
    return {
        filename: "path/to/file" // etc.
    };
}

it really depends on what you want to achieve, but generally a combination of objects and arrays is best.

so you could have something like

var buildFolder = function(){
    return {
        folders: [],
        files: []
    };
};

var buildFile = function(title){
    return {
        title: title
    };
};

var folder = buildFolder();

folder.files.push(buildFile());
folder.files.push(buildFile());
folder.files.push(buildFile());
folder.files.push(buildFile());

folder.folders.push(buildFolder());
folder.folders[0].files.push(buildFile());
Sign up to request clarification or add additional context in comments.

1 Comment

sorry man, your much better at this than I, can you help me translate that. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.