Instead of using a real file structure, is it possible to give it a premade list of strings to have it create a nested list of paths/files for you?
Example List (formatted so it's readable):
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'
]
Here is the output I'm hoping for:
['user'['1.jpg','hey.jpg','folder1'['1.txt','blah.txt','folder2'['random.txt']],'folder3'['folder4'['folder5'['1.txt','2.txt','3.txt']]]]]
I asked a similar question here: How would I nest file path strings into a list based upon matching folder paths in Python
I got a comment saying os.walk()
would be ideal for what I wanted, but everywhere I look, it seems that people are using it to crawl the file system, as opposed to passing it a list of already created file paths.