4

I am not sure how to go about doing this in an angular way.

I would like to implement a file explorer similar to the following: example 1 or example 2

features it should implement are:

  • show files and folders in current directory
  • ability to click on folders to expand them (like in example)

So what i have at the moment is a list of files and folders as an array of paths. This is generated by an onDrop or onChange event (from drag and drop or input).

Any advice on how to implement this?

3 Answers 3

5

Take look at @angular-filemanager

FileNavigator.prototype.buildTree = function(path) {
    var self = this;
    var recursive = function(parent, file, path) {
        var absName = path ? (path + '/' + file.name) : file.name;
        if (parent.name && !path.match(new RegExp('^' + parent.name))) {
            parent.nodes = [];
        }
        if (parent.name !== path) {
            for (var i in parent.nodes) {
                recursive(parent.nodes[i], file, path);
            }
        } else {
            for (var i in parent.nodes) {
                if (parent.nodes[i].name === absName) {
                    return;
                }
            }
            parent.nodes.push({name: absName, nodes: []});
        }
    };

    !self.history.length && self.history.push({name: path, nodes: []});
    for (var i in self.fileList) {
        var file = self.fileList[i].model;
        file.type === 'dir' && recursive(self.history[0], file, path);
    }
};
Sign up to request clarification or add additional context in comments.

Comments

1

Found a solution:

Angular Treeview

Pure AngularJS based tree menu directive.

Comments

0

Try Angular Filesystem Reader.

An angular service implementation to find files by extension(s) asynchronously and synchronously, by traversing the filesystem starting from the specified root directory. Exclusive and/or ignorable directories can be specified as well. Three options available to access the results: callback, Promise (sync) and/or a live array (async).

Comments

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.