# Build a file/directory tree [closed]

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.

• Jul 5 at 9:19
• The distinction between files and directories, as well as the backslash rule, seem needlessly complex Jul 5 at 9:43
• May I assume the path don't contain /../ or /./ in it?
– tsh
Jul 5 at 10:01
• What is expected output? Should I output exactly match the given ascii art? Or which part is necessary?
– tsh
Jul 5 at 10:02
• I suggest using our Sandbox in the future, so the issues like in the above comments are resolved there. Jul 5 at 10:08