js list path info of object

Viewed 746

Im trying to mirror how an S3 bucket works, and im struggling with the UI. So I have a bunch of json as follows

{"name":"sams file", "path":"testfile1.jpg"},
{"name":"sams file", "path":"folder1/testfile2.jpg"},
{"name":"sams file", "path":"folder1/testfile3.jpg"},
{"name":"sams file", "path":"folder2/testfile4.jpg"},
{"name":"sams file", "path":"folder2/testfile5.jpg"},
{"name":"sams file", "path":"folder2/folder3/testfile6.jpg"},

Now i am looking to pass say lodash a value ie folder2, and im wanting it to return all file names in that folder and any folders it contains (not files) so i can build a UI, so im basically looking for an an array of

testfile4.jpg, testfile5.jpg and folder3

I should then be able to check if the item is a file or a folder and present the ui to the user

Does this sound possible, would anyone suggest an easier way to achieve what i want?

Thanks Sam

3 Answers
Related