Data rotation and cleanup
📖 Scenario: You are managing a Raspberry Pi that collects sensor data every day. To save space, you want to keep only the latest 5 days of data files and remove older ones automatically.
🎯 Goal: Build a Python script that lists data files, keeps only the latest 5 files, and deletes older files to clean up storage.
📋 What You'll Learn
Create a list of data file names with dates in the format 'data_YYYYMMDD.txt'.
Set a variable to keep track of how many recent files to keep.
Use a sorting method to find the latest files and select only those to keep.
Print the list of files that will be deleted.
💡 Why This Matters
🌍 Real World
This script helps Raspberry Pi users manage limited storage by automatically cleaning old sensor data files.
💼 Career
Understanding file management and cleanup scripts is useful for system administrators and IoT developers who maintain devices with limited storage.
Progress0 / 4 steps