How to create file tree from list of (str, int)?
I already tried to find ways to solve this problem, but I managed to find code for working with files, not a list of strings.
Example of input:
[
('dir1\\file.exe', 14680064)
('dir1\\file-1.bin', 4293569534)
('dir1\\file-2.bin', 4294967294)
('dir1\\file-3.bin', 4294967294)
('dir1\\archives\\archive1.zip', 5242880)
('dir1\\archives\\archive2.zip', 525788)
]
Result:
dir1
├──file.exe 14680064 Bytes
├──file-1.bin 4293569534 Bytes
├──file-2.bin 4293569534 Bytes
├──file-3.bin 4293569534 Bytes
└──archives
├──archive1.zip 5242880 Bytes
└──archive2.zip 525788 Bytes
You could use pathlib for a lot of what you need.
Given your list of paths and file sizes
paths.Please note that this function does not generate a valid zip file (or any specific file type), so if that is what you want to do, you'll have to implement that specifically.