Class: QgsZipUtils¶
Provides utility functions for working with zip files.
Added in version 3.0.
Methods
Returns the list of files within a zip file |
Static Methods
Extracts a file from a zip archive, returns |
|
Returns |
|
Unzip a zip file in an output directory. |
|
Zip the list of files in the zip file. |
- class qgis.core.QgsZipUtils[source]¶
Bases:
object- static extractFileFromZip(zipFilename: str | None, filenameInZip: str | None)[source]¶
Extracts a file from a zip archive, returns
Trueon success.Added in version 4.0.
- Parameters:
zipFilename (Optional[str])
filenameInZip (Optional[str]) -> (bool)
- files(zip: str | None) List[str][source]¶
Returns the list of files within a
zipfileAdded in version 3.30.
- Parameters:
zip (Optional[str])
- Return type:
List[str]
- static isZipFile(filename: str | None) bool[source]¶
Returns
Trueif the file name is a zipped file ( i.e with a ‘.qgz’ extension,Falseotherwise.- Parameters:
filename (Optional[str]) – The name of the file
- Return type:
bool
- Returns:
Trueif the file is zipped,Falseotherwise
- static unzip(zip: str | None, dir: str | None, checkConsistency: bool = True)[source]¶
Unzip a zip file in an output directory.
- Parameters:
zip (Optional[str]) – The zip filename
dir (Optional[str]) – The output directory
checkConsistency (bool = True) -> (bool) – Perform additional stricter consistency checks on the archive, and error if they fail (since QGIS 3.30)
- Returns:
Falseif the zip filename does not exist, the output directory does not exist or is not writable.files: The absolute path of unzipped files
- static zip(zip: str | None, files: Iterable[str | None], overwrite: bool = False) bool[source]¶
Zip the list of files in the zip file.
If the zip file already exists (and
overwriteisFalse) or is empty, an error is returned. If an input file does not exist, an error is also returned.- Parameters:
zip (Optional[str]) – The zip filename
files (Iterable[Optional[str]]) – The absolute path to files to embed within the zip
overwrite (bool = False) – Set to
Trueto allow overwriting existing files (since QGIS 3.44)
- Return type:
bool