Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Zip-File, wildcards

Tags:

python

I was wondering how I could tell Python to extract only ".txt" files from a zip folder, using a wildcard. This code works fine for me:

extractor.extract("\websitefiles\test.hmtl")"

How can I use this same code to extract all .txt files in that current directory? I was thinking something like this:

extractor.extract(".*.txt")

but it failed to work.. Any ideas???

like image 684
user715578 Avatar asked Dec 07 '25 10:12

user715578


1 Answers

First, you need the file names list, using namelist(). Then, you can filter the "*.txt" files with txtfiles = fnmatch.filter(fn_list,"*.txt") Now you can extract the files one by one:

extracts = [ extractor.extract(txt) for txt in txtfiles ]
like image 198
jarondl Avatar answered Dec 09 '25 23:12

jarondl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!