Task
In this challenge, your task is to write a program or function which takes an array of paths with an additional boolean indicating it is a file or directory and outputs a file/directory tree in any reasonable format.
Remarks
- Some directories can end with a forward slash ("/") but this is not always the case
- A parent directory is not always explicitly defined but should be in the tree
- "." and ".." as file name or directory name are not allowed
- Standard loopholes are not allowed
Input
An unsorted array of paths. Each item is a tuple of path and a boolean which is True for a file and False for a directory.
[ ['Root Folder/Sub Folder/', False], ['Root Folder/Sub Folder/hello.txt', True], ['Root Folder/Sub Folder/SubSub Folder/SubSubSub Folder/', False], ['Root Folder/Sub Folder/world.txt', True], ['Root Folder/Sub Folder 2', False], ] Output
Text formatted example
[D] Root Folder [D] Sub Folder [D] SubSub Folder [D] SubSubSub Folder [F] hello.txt [F] world.txt [D] Sub Folder 2 Data structure formatted example
[ 'Root Folder', [ [ 'Sub Folder', [ [ 'SubSub Folder', [ [ 'SubSubSub Folder', [], [] ] ], [] ] ], ['hello.txt', 'world.txt'] ], [ 'Sub Folder 2', [], [] ] ], [] ] This is a code golf. Shortest code in bytes wins.
/../or/./in it? \$\endgroup\$