A minimal Python script that automatically moves log files older than a week to an "archive" folder.
- Automatic Detection: Finds log files (
.log,.txt,.out) - Age Check: Identifies files older than 7 days
- Archive Creation: Creates archive folder automatically
- Duplicate Handling: Adds timestamps to prevent overwrites
- Sample Generation: Creates test logs for demonstration
python log_archiver.py# Will prompt for directories
python log_archiver.py.logfiles.txtfiles.outfiles
Auto Log File Archiver
=========================
Enter log directory (or press Enter for sample):
Created sample logs in: sample_logs
Enter archive directory (optional):
Scanning: sample_logs
Archived: old.log
Archived 1 log file(s)
- Scan Directory: Looks for log files in specified directory
- Check Age: Uses file modification time to determine age
- Create Archive: Makes "archive" subfolder if needed
- Move Files: Moves files older than 7 days to archive
- Handle Duplicates: Adds timestamp suffix if file exists
The script can create sample logs for testing:
recent.log- Current timestamp (not archived)old.log- 10 days old (gets archived)
- Python 3.6+
- No external dependencies
- Permission errors are caught and reported
- Missing directories show appropriate messages
- File operation errors are handled gracefully
Created for issue #787 - 100 Lines of Python Code Project