I’m using zipfile and tarfile Python modules to open, extract and compress archives.
I need to display the archive structure in a QTreeWidget, and I don’t know how to go on. To get the infos I use the function infos(path) from this file.
I would like to obtain something like this (from Ark):

For example, if I receive this filenames: ('GCI/PyFiles/prova3.py', 'GCI/', 'GCI/PyFiles/', 'GCI/Screenshots/', 'GCI/prova2.py', 'prova.py'), I’d like to obtain this:
- prova.py
- GCI/
|
|- prova2.py
|- PyFiles/
|- prova3.py
|- Screenshots/
in my QTreeWidget.
Thank you,
rubik
I’m not sure how QTreeWidget wants it’s data offhand, but here is a (possibly bad way) to build the structure in memory.
This will give you a dictionary
structurethat for each key is either another dictionary (representing a folder) orNonerepresenting that the key is a file.The better way to do this would create a class like this:
or something like that which you can populate. If I remember correctly from my QT programming days, the QTreeWidget wants a datasource so you basically could figure out what that source looks like and populate it appropriately. There’s also probably the option to do this,
which would return you: