This commit is contained in:
2025-06-06 18:32:09 -03:00
parent 3e44761e69
commit 53613d0a48
34 changed files with 939 additions and 752 deletions

View File

@@ -1,3 +1,10 @@
"""
Extracts all .gz files from a given directory and writes the uncompressed
outputs to an 'out/' subfolder within that directory.
Useful for simple, batch decompression of Gzip files via CLI.
"""
import gzip
from pathlib import Path
@@ -9,15 +16,11 @@ def unzip_gzip(file: Path, target: str):
def unzip_gzfiles(dirpath: Path) -> None:
"""Unzip the .gz files from a dir."""
if not dirpath.exists() or not dirpath.is_dir():
print(f'"{dirpath}" not found')
return None
"""Unzips all .gz files from a given directory into an 'out/' folder."""
gzfiles = list(dirpath.glob('*.gz'))
if not gzfiles:
print(f'No .gz files found in "{dirpath}"')
print(f' No .gz files found in "{dirpath}"')
return None
# Create a directory to output the files
@@ -30,12 +33,19 @@ def unzip_gzfiles(dirpath: Path) -> None:
continue
if unzip_gzip(file, f'{dirpath}/out/{filename}'):
print(f'Unzipped "{file.name}"')
print(f'Unzipped: {file.name}')
if __name__ == '__main__':
try:
dirpath = input('Type the directory path\n')
unzip_gzfiles(Path(dirpath))
except (KeyboardInterrupt, Exception):
print('See ya')
dirpath = Path(input('📂 Enter the directory containing .gz files: '))
if not dirpath.exists() or not dirpath.is_dir():
print(f'❌ Directory "{dirpath}" not found or is not a folder.')
exit(1)
unzip_gzfiles(dirpath)
except KeyboardInterrupt:
print('\n👋 Cancelled by user')
except Exception as e:
print(f'💥 Error: {e}')