> ## Documentation Index
> Fetch the complete documentation index at: https://docs.virusstudio.in/llms.txt
> Use this file to discover all available pages before exploring further.

# Automation Scripts: Python Files, Tasks & Bots Explained

> Discover what automation scripts can do for you — from bulk file renaming and scheduled tasks to Discord bots — with Python and Bash examples to start.

Automation scripts take care of repetitive, time-consuming tasks so you do not have to do them manually. Whether you need to rename hundreds of files at once, send a report every morning, scrape a website for data, or run a Discord bot that manages your server, a well-written script can do it reliably every single time. Virus Studio writes automation scripts tailored to your exact workflow — this guide explains the possibilities and shows you what that code actually looks like.

## What Automation Scripts Can Do

Here is a snapshot of the most common categories we handle:

* **File and folder management** — bulk rename, sort, move, or delete files based on rules you define
* **Web scraping** — extract data from websites and save it to a spreadsheet or database
* **Scheduled tasks** — run a script at a set time or on a repeating interval (daily backups, weekly reports, etc.)
* **Discord bots** — respond to commands, moderate servers, post announcements, sync roles, and more
* **API integrations** — connect services together (e.g. post a tweet when a new YouTube video uploads)
* **Data processing** — clean, transform, and analyse CSV or JSON files automatically
* **System utilities** — monitor CPU/RAM usage, auto-restart crashed processes, clean temp files

## Python File-Rename Automation

Python is our go-to language for automation because of its readability and enormous library ecosystem. The script below renames every `.txt` file in a folder by prepending today's date — a common request for log archival.

```python theme={null}
import os
from datetime import datetime

# --- Configuration ---
TARGET_FOLDER = r"C:\Users\You\Documents\Logs"  # Change to your folder path
FILE_EXTENSION = ".txt"
DATE_PREFIX = datetime.now().strftime("%Y-%m-%d")

# --- Rename Loop ---
renamed_count = 0

for filename in os.listdir(TARGET_FOLDER):
    if filename.endswith(FILE_EXTENSION) and not filename.startswith(DATE_PREFIX):
        old_path = os.path.join(TARGET_FOLDER, filename)
        new_name = f"{DATE_PREFIX}_{filename}"
        new_path = os.path.join(TARGET_FOLDER, new_name)

        os.rename(old_path, new_path)
        print(f"Renamed: {filename}  →  {new_name}")
        renamed_count += 1

print(f"\nDone. {renamed_count} file(s) renamed.")
```

On macOS or Linux, replace the `TARGET_FOLDER` path with a Unix-style path like `/home/you/logs`.

## Python Scheduled Task Example

You can run a task on a repeating schedule using the `schedule` library or a simple `time.sleep` loop. The example below checks a folder for new files every 60 seconds and logs their names.

```python theme={null}
import os
import time
from datetime import datetime

WATCH_FOLDER = "/home/you/incoming"
CHECK_INTERVAL = 60  # seconds
seen_files = set()

def check_for_new_files():
    current_files = set(os.listdir(WATCH_FOLDER))
    new_files = current_files - seen_files

    for filename in new_files:
        timestamp = datetime.now().strftime("%H:%M:%S")
        print(f"[{timestamp}] New file detected: {filename}")
        # Add your processing logic here (move, parse, notify, etc.)

    seen_files.update(new_files)

print(f"Watching '{WATCH_FOLDER}' every {CHECK_INTERVAL}s. Press Ctrl+C to stop.\n")

while True:
    check_for_new_files()
    time.sleep(CHECK_INTERVAL)
```

For more complex schedules (e.g. "run every weekday at 9 AM"), the `schedule` library or system-level tools like **cron** (Linux/macOS) and **Task Scheduler** (Windows) are the right choice — just mention your schedule when you submit a request.

## Bash / Shell Automation

For quick system tasks on Linux or macOS, a Bash script is often the fastest solution. Here is an example that deletes log files older than 30 days:

```bash theme={null}
#!/bin/bash

LOG_DIR="/var/log/myapp"
DAYS_OLD=30

echo "Cleaning logs older than ${DAYS_OLD} days in ${LOG_DIR}..."
find "$LOG_DIR" -name "*.log" -mtime +$DAYS_OLD -exec rm -v {} \;
echo "Cleanup complete."
```

You can schedule this with a cron job to run automatically every night — no manual effort needed.

<Tip>
  **Describe your automation in plain English when you submit a request.** You do not need to know which libraries or tools to use — that is our job. Simply tell us *what* you want the script to do, *when* it should run, and *what* the input and output look like. For example: *"I have a folder of MP3 files. I want to rename them all so the artist name comes first, then the track title, based on the filename which is currently `trackTitle_artistName.mp3`."* The more detail you give, the faster we can deliver exactly what you need.
</Tip>

<Info>
  **We write scripts for Windows, macOS, and Linux.** Just let us know which operating system (or systems) the script needs to run on, and we will make sure it works correctly for your environment — including handling file path formats, OS-specific commands, and any platform differences.
</Info>

***

## Ready to Get Started?

<CardGroup cols={2}>
  <Card title="Submit a Request" icon="file-code" href="/getting-started/submitting-a-request">
    Tell us what you need automated and we will write a clean, tested script for you.
  </Card>

  <Card title="Debugging Tips" icon="bug" href="/guides/debugging-tips">
    If a script you already have is not working, learn how to read error messages and describe the issue clearly.
  </Card>
</CardGroup>
