To documentation states that the first parameter of ZipFile
must be:
A string with the path to a ZIP archive
import zipfile
zf = zipfile.Zipfile("path/para/arquivo.zip")
An object file-like
import zipfile
with open("path/para/arquivo.zip", rb) as f:
zf = zipfile.Zipfile(f)
An object Path-like
import zipfile
from pathlib import Path
p = Path("path/para/arquivo.zip")
zf = zipfile.Zipfile(p)
And in your case, it’s none of them, because you’re passing a list of paths. The module ends up treating its list as a file, and mistakenly tries to invoke the method seek
belonging to objects file-like.
For your code to work, just run your code for each element of the list instead of the entire list.
Your modified example would be:
for path in encontraArquivosEmPastaRecursivamente('.zip', 'C:\\Users\\x\\Downloads'):
zipado = zipfile.ZipFile(path)
zipado.extractall()
PS: It is worth checking the method security note extractall
, follows a free translation:
Warning:
Never extract files from unreliable sources without proper inspection.
It is possible that files are created outside the folder, for example members that have absolute filenames starting with /
or names with ..
.
This module tries to prevent this.