To batch rename file copies from a CSV on Mac, keep two columns named old_name and new_name and use Python to validate each assignment. Run the preview first, then use the same CSV to write renamed copies into a new folder. Each saved copy is checked against the contents of its source file.

Decide which files and names belong in the mapping

Use an explicit mapping when the filenames need individual assignments, such as a folder of scans whose approved new names come from an inventory. This is useful when files end with different case numbers, when the order from Finder changes, or when the recipient requires names that cannot be generated from one shared rule. The mapping should contain the exact current name and exact requested name for each file.

The script works on individual files from a single source folder. It writes into a new output folder outside that source folder. For a test, make a folder named Source files containing two small files called scan 1.txt and scan 2.txt. Put a different known phrase in each one. The exercise checks both naming and identity. You should be able to tell immediately if the contents assigned to the two names were swapped.

In Finder, choose Finder → Settings → Advanced → Show all filename extensions if you need to see full names. For the manifest, use plain filenames with extensions, including any spaces and punctuation that are genuinely present. Enter one row per source. Choose a unique destination name per row. Save the mapping as UTF-8 CSV outside the folder you plan to send.

old_name,new_name
scan 1.txt,"01, intake.txt"
scan 2.txt,02 review.txt

Read the exported CSV in a text editor before proceeding. The first row should contain the two headers in the order shown above. The first destination intentionally contains a comma, which a CSV field encloses in quotes. Spreadsheet apps may display the input differently from the saved text, especially when a label starts with zeros. Verify the values in the CSV you will run. Python’s documentation for quoting and reading CSV

If the inventory contains more entries than you intend to deliver, make a mapping containing the selected rows only. For example, a folder with 40 scans may support a request for only 12 of them. The output should contain those 12 copies with the specified names. Count the selected rows before starting and check that this is the set the recipient expects. Files omitted from the CSV stay in the source directory and have no output assignment.

Save a script that checks the entire CSV first

Use an installed Python 3 interpreter. Run python3 –version in Terminal to verify that the command works before preparing a larger batch. Save the script below as rename_copies.py. It uses the Python standard library. It validates every data row before creating any output folder, with checks for exact source names, safe filenames, repeated source rows, incompatible extensions, and colliding output names.

import argparse
import csv
import hashlib
import shutil
import unicodedata
from pathlib import Path


def leaf_name(name):
    return (
        bool(name)
        and name == name.strip()
        and name not in {".", ".."}
        and name.isprintable()
        and not any(character in name for character in "/\\:")
        and not name.endswith(".")
    )


def digest(path):
    checksum = hashlib.sha256()
    with path.open("rb") as file:
        for block in iter(lambda: file.read(1024 * 1024), b""):
            checksum.update(block)
    return checksum.digest()


def load_plan(mapping, source):
    files = {
        path.name: path for path in source.iterdir()
        if path.is_file() and not path.is_symlink()
    }
    plan = []
    old_names = set()
    target_keys = set()
    with mapping.open(encoding="utf-8-sig", newline="") as file:
        rows = csv.reader(file, strict=True)
        if next(rows, None) != ["old_name", "new_name"]:
            raise ValueError("Expected the header old_name,new_name")
        for row in rows:
            location = f"CSV line {rows.line_num}"
            if len(row) != 2 or not all(leaf_name(name) for name in row):
                raise ValueError(f"{location}: expected two plain filenames")
            old, new = row
            if old not in files:
                raise ValueError(f"{location}: source was not found exactly: {old!r}")
            if old in old_names:
                raise ValueError(f"{location}: duplicate source: {old!r}")
            if Path(old).suffix.casefold() != Path(new).suffix.casefold():
                raise ValueError(f"{location}: keep the source file extension")
            key = unicodedata.normalize("NFC", new).casefold()
            if key in target_keys:
                raise ValueError(f"{location}: colliding output name: {new!r}")
            old_names.add(old)
            target_keys.add(key)
            plan.append((files[old], new))
    if not plan:
        raise ValueError("The CSV needs at least one data row")
    return plan


def main():
    parser = argparse.ArgumentParser(description="Make renamed copies from a CSV")
    parser.add_argument("mapping", type=Path)
    parser.add_argument("source", type=Path)
    parser.add_argument("output", type=Path)
    parser.add_argument("--apply", action="store_true")
    args = parser.parse_args()
    try:
        source = args.source.expanduser().resolve(strict=True)
        if not source.is_dir():
            raise ValueError("The source must be a folder")
        output_path = args.output.expanduser()
        if output_path.exists() or output_path.is_symlink():
            raise ValueError("Use a new output folder name")
        output = output_path.resolve()
        if source == output or source in output.parents:
            raise ValueError("Choose an output folder outside the source")
        if not output.parent.is_dir():
            raise ValueError("The output folder's parent must already exist")

        plan = load_plan(args.mapping.expanduser(), source)
        for original, new in plan:
            print(f"{original.name!r} -> {new!r}")
        if not args.apply:
            print(f"Preview: {len(plan)} planned copies.")
            return

        output.mkdir(exist_ok=False)
        for original, new in plan:
            target = output / new
            with original.open("rb") as incoming, target.open("xb") as outgoing:
                shutil.copyfileobj(incoming, outgoing)
            if digest(original) != digest(target):
                raise ValueError(f"Contents do not match: {target.name!r}")
        print(f"Verified {len(plan)} copies in {output}")
    except (OSError, ValueError, csv.Error) as error:
        parser.exit(1, f"{error}\n")


if __name__ == "__main__":
    main()

The mapping is read as text, with support for the UTF-8 byte-order mark that some spreadsheet exports include. The script uses case-insensitive, normalized comparison when checking target name collisions. As a result, it rejects two destination names that differ only by capitalization or an equivalent Unicode form. That gives the batch a predictable set of names on a typical Mac volume. The original column still uses exact spelling and case as read from the source directory.

The output check compares bytes using SHA-256 after both files have been closed. This means a copied JPEG stays a JPEG and a copied PDF stays a PDF. The method copies the file contents. Filesystem properties such as Finder tags or modification times can differ on the new copy, so use this recipe when the document bytes and the final name are the delivery requirements. Python’s file-copy functions · Python’s hashing interface

Preview the mapping from Terminal

Put rename_copies.py, name-map.csv, and Source files beside one another. Open Terminal in that parent folder, then run:

python3 rename_copies.py name-map.csv "Source files" "Named output"

The preview prints each planned source and destination pair and the total count. The two-row test should display scan 1.txt going to 01, intake.txt and scan 2.txt going to 02 review.txt. Check that there is no output folder yet. The quoted arguments tell the shell that each folder name is a single path. If your folders live elsewhere, use their full paths instead.

For a batch from a real inventory, compare the preview count to the number of rows you intend to deliver. Spot-check the rows most likely to be confused, such as consecutive identifiers, repeated titles, or names with spaces and commas. A correct preview still depends on correct assignments in your CSV. The script checks that the source and target names make sense as filenames, while the inventory audit checks that each requested title describes the correct source.

Verify that a bad row stops the whole preview

Save a separate copy of the practice map and change the second destination to 01, INTAKE.txt, keeping that field quoted. The two destination names now differ only in case. Run the preview using the changed CSV and a new output folder name. You should see an error about a colliding output and no new folder in Finder. The original practice map still provides the working two-row example.

In a different copy of the map, replace one destination with Archive/02 review.txt. The script expects just a filename and should report the row as invalid. Replacing the old filename with one that does not exist should produce a missing-source error. Replacing 02 review.txt with 02 review.pdf should report that the extension must match. Use each check on a copy of the sample mapping so you can tell which validation produced the message.

Reopen the valid two-row CSV and repeat the preview. The expected two mappings should return. If you changed the sample files while testing, confirm that they still have their distinct phrases. This exercises the two things that matter before a real delivery. The batch can reject a malformed assignment, and the corrected plan can map each source to one intended output.

Apply the same plan and verify the copies

When the preview matches your mapping, run the same command with –apply:

python3 rename_copies.py name-map.csv "Source files" "Named output" --apply

Keep the input folder stable while the copies are being created. The script rechecks the mapping and creates the destination folder only after validation. Exclusive creation prevents writing over a file that already has the target name. Wait for the line reporting Verified 2 copies in the test. If you get an error before that line, treat the batch as incomplete. Python’s documentation for opening files in exclusive creation mode

In Finder, open Named output and confirm that both requested names exist. Open the two practice files and compare the phrases with the matching files in Source files. Then check the source folder and confirm that the old names are there. When the batch contains many files, check the count and sample files with recognizable contents in addition to using the script’s byte comparisons. This confirms that your mapping and your delivery folder refer to the same matching set.

When several people can edit the source, make a stable local copy of the input folder for the batch. Cloud files can be edited or downloaded while you work. A checksum mismatch means the two byte sequences read by the script differed and needs investigation. If another process edits a document following verification, it can also make the completed work folder stale. Use the same source and map for the approved preview and write, then review the output before making later changes.

Correct a mapping problem and run a fresh preview

If you see source was not found exactly, open the source folder and check the name character by character. Pay attention to a hidden extension, a different character that looks like a hyphen, or a difference in capitalization. Folders and symbolic links are outside this script’s source selection. For a Finder alias that appears as a file, identify the actual document it refers to and use that document. Copying the bytes of an alias would produce another alias file.

If you see colliding output name, locate the rows that specify versions of the same target name. Give each a clearly distinct name and check for duplicate source rows. If a source needs two different deliveries, organize those as separate runs with their own output folders. Unique target names and source rows make the count meaningful when you audit a completed batch.

Check any naming rules from the destination alongside the preview. A portal might require a particular case number pattern or limit the length of the filename. A name the Mac accepts can still exceed that requirement. If the recipient supplies an approved spreadsheet, compare the printed destinations against that sheet before applying the batch. Correct the manifest and preview again when any row differs.

After adjusting the CSV, run the preview again. If an earlier write was interrupted, use a new output folder name for your new attempt. The partial folder can help you understand where the interruption occurred, and the final verified folder should contain the complete result of a single run. A successful handoff consists of the checked output folder and the exact CSV used for it. For filenames generated by one shared rule, use Finder’s built-in batch rename command.

If you need two delivery sets with different naming assignments, keep a separate manifest for each set. A folder name that identifies the requested version helps you select the right batch in an upload form. Store the manifests with your working records so you can tell which file corresponds to each requested name later. If the original names contain private information, review which records the recipient needs before including the manifest in the delivery.