javascript - Simulate File System in JSON -


i'm trying imitate file system in json. purpose detect whether "file" exists or not. thinking of structure this:

var fs = {   somename: {     type: 'directory',     contents: {       somenamechild: {         type: 'directory',         contents: {           somechild: {             type: 'file',             contents: 'hello world!'           }         }       }     }  } } 

after seeing started wondering if knows of simulate file system in-memory in json. don't want have write of createdirectory, createfile, removedirectory, removefile, etc. file operatons. don't need robust in terms of file storage. i'm more interested in directory structure operations.

does know of code can this? figure has tackled this.

thanks!

a dictionary has need, explicit type fields should not needed, @ least not if scope folders , files.

{    foldera : {        foldernested : {            somefile : "foo content"        },         foldernestedb : {         },    } } 

you have implement directory operations, pretty straightforward. example, navigate path in file system simply

var pieces = path.split('/');  var node = root;  (var = 0; < pieces.length; ++i) {     node = node[pieces[i]];     if (!node) {        // error, not found     }     break; }  // |node| file/folder 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -