how to search .zip files in a specific folder and then extract data from a .txt file inside it [closed]

StackOverflow https://stackoverflow.com/questions/21819742

  •  12-10-2022
  •  | 
  •  

Question

Important information: I'm doing this in Ubuntu (13.10) and am out of my league on this project, but pushing my knowledge is how I like to learn.

I'm wanting to make a program that when it is started runs a script that scans a specific folder (etc/UIManager/saves) for .zip files that each contain a specific text file called "data.txt" It then takes the data in them (UIname, Version, Compatibility) and puts it out in a single line horizontal table

Unity | 3.2.5 | 13.10

I'd want this done with multiple .zip files. The list of those is refreshed each time the program is started. The name for the .zip files is not pre-determined.

This is what the user would see in the program's window if they had these three saved in the folders (The '|' is just there to separate the data and is not necessary):

Unity | 3.2.5 | 13.10

KDE | 4.1.0 | 13.10

Gnome | 3.5.7 | 13.10

The text files would look like this and are all named data.txt:

UIname= x

Version= major, minor, dev release

compatibility= Ubuntu versions they are compatible with

The language I'd like this to be done in is preferably Python 3, but any C language is fine too. If it would be easier or more practical in another language I'm open to suggestions. To see what my main goal is: http://www.youtube.com/watch?v=mERSAYhN80U The part I'm working on now is what you saw in that first window where there were two UI's displayed

Was it helpful?

Solution

Use glob(http://docs.python.org/3/library/glob.html) to match all zip files. Iterate over this array. Extract data with zipfile (http://docs.python.org/3/library/zipfile.html). Data file may be parsed with configparser (http://docs.python.org/3/library/configparser.html) if compatible syntax.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top