A Python service that automatically monitors a directory for new compressed files (.zip, .rar, .7z), decompresses them to a specified output directory, and removes the original compressed files.
- Real-time monitoring of a directory for new compressed files
- Support for ZIP, RAR, and 7z file formats
- Smart download completion detection: Waits for files to finish downloading before attempting decompression
- Password support: Automatically tries default passwords for password-protected archives
- Automatic decompression to a specified output directory
- Removal of original compressed files after successful decompression
- Comprehensive error handling and logging
- Docker support for easy deployment
The system now intelligently waits for files to complete downloading before attempting decompression:
- Skips files with 0 bytes size
- Monitors file size changes every 5 seconds
- Only processes files after size remains stable for 30 seconds
- Prevents decompression failures due to incomplete downloads
- Accepts a list of default passwords via command line or environment variables
- Tries passwords sequentially when encountering password-protected archives
- Supports password-protected ZIP, RAR, and 7z files
- Logs successful password usage for audit purposes
- Gracefully handles exhausted password attempts
- Python 3.6+
- Docker (for containerized deployment)
-
Clone the repository:
git clone <your-repository-url> cd file-auto-decompressor
-
Install the required Python packages:
pip install -r requirements.txt
-
Install system dependencies:
- For Ubuntu/Debian:
sudo apt-get update && sudo apt-get install -y p7zip-full unrar - For macOS:
brew install p7zip unrar
- For Windows: Install 7-Zip and WinRAR, and ensure they are in your PATH.
- For Ubuntu/Debian:
-
Clone the repository:
git clone <your-repository-url> cd file-auto-decompressor
-
Build the Docker image:
docker build -t file-auto-decompressor .
Run the script with default settings:
python main.pyCustomize the input and output directories:
python main.py --input-dir /path/to/downloads --output-dir /path/to/outputEnable file logging:
python main.py --log-dir /path/to/logsSet a different log level:
python main.py --log-level DEBUGUse default passwords for password-protected archives:
python main.py --default-passwords "password123,admin,123456"Combine multiple options:
python main.py \
--input-dir /path/to/downloads \
--output-dir /path/to/output \
--default-passwords "password123,admin,secret" \
--log-level INFORun the container with default settings:
docker run -d \
-v /path/to/downloads:/downloads \
-v /path/to/output:/download_files \
--restart always \
--name file-auto-decompressor \
file-auto-decompressor-
Edit the docker-compose.yml file to specify your directory paths:
volumes: - /path/to/downloads:/downloads # Change this to your downloads directory - /path/to/output:/download_files # Change this to your output directory
-
(Optional) Create a
.envfile to set default passwords:# Copy the example file and edit it cp example.env .env # Edit .env to set your passwords
-
Run with Docker Compose:
docker-compose up -d
To use default passwords with Docker Compose, you can:
Option 1: Use environment file (.env)
# Create .env file
echo "DEFAULT_PASSWORDS=password123,admin,123456" > .env
docker-compose up -dOption 2: Set environment variable directly
DEFAULT_PASSWORDS="password123,admin,123456" docker-compose up -dOption 3: Run container manually with passwords
docker run -d \
-v /path/to/downloads:/downloads \
-v /path/to/output:/download_files \
-e DEFAULT_PASSWORDS="password123,admin,123456" \
--restart always \
--name file-auto-decompressor \
file-auto-decompressorThe application can be configured using command-line arguments:
--input-dir: Directory to monitor for new compressed files (default: /downloads)--output-dir: Directory where decompressed files will be saved (default: /download_files)--log-dir: Directory where log files will be stored (default: None, logs to console only)--log-level: Logging level (default: INFO, options: DEBUG, INFO, WARNING, ERROR, CRITICAL)--default-passwords: Comma-separated list of default passwords to try for password-protected archives (default: empty)
When using Docker, you can also configure the application using environment variables:
DEFAULT_PASSWORDS: Same as--default-passwordscommand-line argument
The download completion detection uses these default settings:
- Stability duration: 30 seconds (file size must remain unchanged)
- Check interval: 5 seconds (how often to check file size)
- Max retries: 3 attempts before giving up on unstable files
These settings are currently hardcoded but provide robust detection for most download scenarios.