# VGMDB Renamer — Wildcard Catalog Number

> **Status:** Active
> **Category:** File Organization
> **Language:** PowerShell
> **Script file:** `rename-catnumber-wildcard.ps1`

## Purpose

Bulk-renames album folders by matching a catalog number pattern (wildcard search) against all subfolders in the current directory tree, then renaming each match to a fully specified target name. Reads rename pairs from a plain-text file and writes a timestamped log of every action.

## Requirements

PowerShell 5.1 or later (no additional modules required).

## Input

| Item | Description | Example |
|------|-------------|---------|
| `rename.txt` | Pipe-delimited file in the same directory as the script | See format below |
| Current directory | Script searches recursively from `.` — run from the root of your music library | `cd "D:\Music"` |

### `rename.txt` format

Each line contains two fields separated by `|`:

```
<catalog_number_or_pattern>|<exact_new_folder_name>
```

The left side is treated as a regex pattern (with special characters automatically escaped), so a bare catalog number like `BCXA-1336` will match any folder whose name contains that string.

```
BCXA-1336|Aqours ORIGINAL SONG CD 7 {72090}
BCXA-1441|Aqours Original Song CD {85984}
BMCV-5009|Shoudou  B'z {126726}
BGCH-1016|Eien no yume ni mukatte  Maki Ohguro {76653}
```

## Output

| Item | Description |
|------|-------------|
| Renamed folders | Each matched folder is renamed in place to the value on the right side of `\|` |
| Timestamped log | `rename_YYYY-MM-DD_HHMMSS_UTC±HHMM.log` written to the working directory |

## Usage

```powershell
# Run from the root of your music library
cd "D:\Music"
.\rename-catnumber-wildcard.ps1
```

The script pauses at the end with `Press Enter to continue...` so you can review the output before the window closes.

## Examples

```powershell
# Example 1 — Standard run: rename all folders listed in rename.txt
cd "D:\Music\FLAC"
.\rename-catnumber-wildcard.ps1

# Example 2 — Run from a specific path without changing directory
Set-Location "E:\Archive\Singles"
& "C:\scripts\vgmdb-renamer-wildcard\rename-catnumber-wildcard.ps1"
```

### What happens per line in `rename.txt`

1. The script searches all subfolders recursively for any folder whose name matches the pattern on the left.
2. If no folder is found, an error is logged and the line is skipped.
3. If the target name already exists, the rename is skipped to avoid collisions.
4. Otherwise the folder is renamed using long-path support (`\\?\` prefix) to handle paths over 260 characters.

### Console output colours

| Colour | Meaning |
|--------|---------|
| Green (`Success`) | Folder renamed successfully |
| Red (`Error`) | Folder not found, target already exists, or rename failed |
| Cyan | Folder being checked |

## Notes

- The script reads `rename.txt` with **UTF-8 encoding** — ensure your file is saved as UTF-8 if it contains non-ASCII characters (Japanese titles, etc.).
- Long path support is built in via the `\\?\` prefix, so paths exceeding the 260-character Windows limit are handled correctly.
- The pattern on the left side of `|` is regex-escaped before matching, meaning characters like `[`, `]`, and `.` are treated as literals.
- If multiple folders match the same pattern, **all** of them will be renamed to the same target name. This will cause the second rename to be skipped (target already exists). Use specific enough patterns to avoid ambiguous matches.
- The log file is created fresh on each run (not appended).

## Related Scripts

- [vgmdb-url-rename-combo-python](vgmdb-url-rename-combo-python.md) — renames folders and simultaneously creates VGMdb `.url` shortcut files inside them
