GeoEco.DataManagement.Files.File.Decompress
- classmethod File.Decompress(compressedFile, destinationDirectory, overwriteExisting=False, decompressedFileToReturn=None)
Decompresses a file into a directory.
- Parameters:
compressedFile (
str) –File to decompress.
The file must be in a supported compression format. The formats presently supported are:
.bz2- a single file compressed in bzip2 format.gz- a single file compressed in gzip format.tar- one or more files archived in UNIX tar format.zip- one or more files archived and compressed in ZIP format.Z- a single file compressed in UNIX “compress” format
tarfiles that are compressed in bzip2 (.tar.bz2), gzip (.tar.gz) or compress format (.tar.Z) are automatically handled. Minimum length꞉ 1. Must exist.destinationDirectory (
str) – Directory to receive the decompressed files. The directory will be created if it does not already exist. Minimum length꞉ 1.overwriteExisting (
bool, optional) – If True, the extracted destination files will be overwritten, if they already exist. If False, aValueErrorwill be raised if any destination files already exist.decompressedFileToReturn (
str, optional) –File name or wildcard pattern that identifies the decompressed file to return.
If the compressed file is not an archive (a format that allows multiple files to be stored within a single archive file) this parameter is ignored, and the path of the single decompressed will be automatically returned. It will have the same file name as the compressed file, minus the extension.
If the compressed file is an archive and this parameter is not provided, nothing is returned.
If the compressed file is an archive and a plain filename is provided for this parameter, the path of that decompressed file will be returned.
If the compressed file is an archive and a wildcard pattern is provided for this parameter, the path of the decompressed file matching that pattern will be returned. The pattern must match exactly one decompressed file or a
ValueErrorwill be raised.If the archive includes subdirectories, the filename or wildcard pattern must account for this. For example, if the archive includes these files:
variables.txt data\chl.txt data\sst.txt data\bathy.txt
then the
bathy.txtfile must be specified asdata\bathy.txt, notbathy.txt. On the other hand,variables.txtdoes not occur in a subdirectory, so it should be specified asvariables.txt.If the destination directory already contains files and directories other than those extracted from the archive, they are candidates to be returned. Beware of this, lest your filename or wildcard pattern return a pre-existing file rather than a newly-extracted one.
The wildcard syntax is the “glob” syntax used by UNIX shells. The
*character matches zero or more characters. The?character matches exactly one character. The[]sequence may be used to match exactly one character within a range. For example, if the following files were decompressed:chl_1992_013.txt chl_1992_01.txt chl_1992.txt chl_summary.txt sst_1992_013.txt sst_1992_01.txt sst_1992.txt sst_summary.txt
The file
chl_1992_01.txtcould be identified by the patterns:chl_1992_01.txt chl_????_??.txt chl*_??.txt chl*_[0-9][0-9].*
Minimum length꞉ 1.
- Returns:
Path of the decompressed file.
If the compressed file is not an archive (a format that allows multiple files to be stored within a single archive file), the path of the single decompressed will be returned. It will have the same file name as the compressed file, minus the extension.
If the compressed file is not an archive, the returned file is specified by decompressedFileToReturn.
- Return type: