Rainbow Creative Designs

Helping individuals & businesses bring their ideas to life through clear communication, creative design, and functional web solutions.

Programming

Problem Decomposition & Scripting Logic

Automation, Logic-Based Problem Solving, and System Optimization

My approach to programming is rooted in system efficiency. Before writing a single line of code, I map out the manual workflow to identify bottlenecks. I focus on creating modular scripts that are easy to debug and scale.

It’s been noticed that user workstations are slowing down because of bloated Downloads and Temp folders. Let’s build a script that “audits” these folders and cleans up old files.

import os
import time

# 1. Define where the "clutter" lives
target_folder = "C:/Users/Downloads/Temp_Cleanup" 
days_limit = 30

# 2. Calculate the "expiry" timestamp
seconds_in_day = 86400
expiration_time = time.time() - (days_limit * seconds_in_day)

# 3. The Logic Loop
def run_hygiene_audit():
    print(f"--- Starting System Hygiene Audit for: {target_folder} ---")
    
    for filename in os.listdir(target_folder):
        file_path = os.path.join(target_folder, filename)
        
        # Check if it's a file and how old it is
        if os.path.getmtime(file_path) < expiration_time:
            print(f"Action: Archiving old file -> {filename}")
            # In a real scenario, we would use os.remove() or move the file
        else:
            print(f"Action: Keeping recent file -> {filename}")

run_hygiene_audit()
  • Modular Design: Created a reusable function (run_hygiene_audit) so the cleanup logic can be called on different schedules or directories without rewriting code.
  • Time-Based Logic: Utilized Python’s time and os libraries to calculate file ages mathematically, ensuring only truly stale data is targeted.
  • Safety First: Designed the script to “print” actions first—a common Tier 2 best practice to verify logic before performing permanent deletions on a system.

Technical Breakdown

  • Logic Type: Iterative Audit — The script loops through a target directory to evaluate each file individually.
  • Safety Protocol: Read-Only Verification — Currently configured to report status to the console to prevent accidental data loss during the testing phase.
  • Scalability: Modular Design — The cleanup parameters (file age and path) are stored as variables, making the script easily adaptable for different server environments.