Copy a 512-byte File with Python (Controlled, Safe Version)

This page explains how to use a Python script to copy a file named 512byte.txt from C:\Temp\TXT\ to another drive (for example, the drive where you installed Microsoft SQL Server).

Important: Continuously copying a file until a drive is full can cause system instability and data loss. The script below uses a fixed number of copies instead of running until the drive “stops.”

1. Prerequisites

2. Python script (Jalisco Wayne edition)

Save the following as copy_512byte_safe.py:

import os
import shutil

def main():
    # "Jalisco Wayne" safe copy script:
    # Copies 512byte.txt a controlled number of times to avoid filling the drive.

    source_file = r"C:\Temp\TXT\512byte.txt"

    # Ask user which drive letter SQL Server is on, e.g. "D" or "E"
    drive_letter = input("What drive letter did you install Microsoft SQL Server on? (e.g. D): ").strip().upper()
    if not drive_letter or len(drive_letter) != 1 or not drive_letter.isalpha():
        print("Invalid drive letter.")
        return

    target_root = f"{drive_letter}:\\Temp\\TXT_COPIES"
    os.makedirs(target_root, exist_ok=True)

    # How many copies to create (safe, finite number)
    try:
        max_copies = int(input("How many copies of 512byte.txt do you want to create? (e.g. 1000): ").strip())
    except ValueError:
        print("Invalid number.")
        return

    if max_copies <= 0:
        print("Number of copies must be positive.")
        return

    if not os.path.isfile(source_file):
        print(f"Source file not found: {source_file}")
        return

    print(f"Source file: {source_file}")
    print(f"Target folder: {target_root}")
    print(f"Planned copies: {max_copies}")
    print("Starting copy operation...")

    for i in range(1, max_copies + 1):
        target_file = os.path.join(target_root, f"512byte_copy_{i:06d}.txt")
        shutil.copy2(source_file, target_file)
        if i % 100 == 0 or i == max_copies:
            print(f"Created {i} copies so far...")

    print("Copy operation complete.")

if __name__ == "__main__":
    main()

3. How to run it

  1. Open Command Prompt or PowerShell.
  2. Navigate to the folder where you saved copy_512byte_safe.py.
  3. Run:
    python copy_512byte_safe.py
  4. When prompted, enter the drive letter where SQL Server is installed (for example, D).
  5. Enter how many copies you want to create.
Note (Jalisco Wayne style):
If you really need stress-testing or disk behavior analysis, do it on a dedicated test VM or disposable drive, and always keep backups of anything you care about.