import zipfile
target = 'OLD-BACKUP.zip'
handle = zipfile.ZipFile(target)
for x in handle.namelist():
if x.endswith('.cat'):
handle.extract(x, 'UNPACK-SPECIFIC')
This Python code uses the zipfile
module to extract specific files from a ZIP archive called 'OLD-BACKUP.zip' that have the file extension .cat
to a specific directory 'UNPACK-SPECIFIC'.
The zipfile.ZipFile
method is used to create a handle to the specified ZIP file. The namelist
method is then called on the handle to get a list of all the filenames in the ZIP archive. A for
loop is then used to iterate through each filename in the list.
For each filename, an if
statement checks if the filename ends with the string '.cat'. If it does, the extract
method is called on the handle to extract that specific file to the directory 'UNPACK-SPECIFIC'.
Note that if the target directory already contains a file with the same name as the file being extracted, it will be overwritten.
No comments:
Post a Comment