I just asked a similar question, however this is a bit different.
This time I'm trying to basically create a nested file tree structure in a list. Lets say I have this list:
files = [
'user/hey.jpg',
'user/folder1/1.txt',
'user/folder1/folder2/random.txt,'
'user/folder1/blah.txt',
'user/folder3/folder4/folder5/1.txt',
'user/folder3/folder4/folder5/3.txt',
'user/folder3/folder4/folder5/2.txt',
'user/1.jpg'
]
Im looking to get this output (not concerned about the order), I may not have formatted this list correctly but here is a general concept:
['user'['1.jpg','hey.jpg','folder1'['1.txt','blah.txt','folder2'['random.txt']],'folder3'['folder4'['folder5'['1.txt','2.txt','3.txt']]]]]
I'd like to essentially make a list which represents a file tree. For example:
user
-folder1
--folder2
---random.txt
--1.txt
--blah.txt
-folder3
--folder4
---folder5
----1.txt
----2.txt
----3.txt
-1.jpg
-hey.jpg
All help is greatly appreciated!