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???
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 ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With