# vgmdb-cuefixer-reverse

> **Status:** Active
> **Category:** Audio & CUE Tools
> **Language:** Python 3
> **Script file:** `vgmdb-cuefixer-reverse.py`

## Purpose

Reverts changes made by [vgmdb-cuefixer](vgmdb-cuefixer.md) by restoring `.cue.bak` backup files to their original `.cue` names, effectively undoing any `FILE` directive edits.

## Requirements

### Dependencies

Python standard library only — no `pip` installs required.

```
os  (built-in)
```

## Input

| Item | Description | Example |
|------|-------------|---------|
| Root directory | Hardcoded `root_dir` variable inside the script | `C:\trial` |
| `.cue.bak` files | Backup files previously created by `vgmdb-cuefixer` | `Album.cue.bak` |

## Output

| Item | Description |
|------|-------------|
| Restored `.cue` files | Each `.cue.bak` is renamed back to `.cue` |
| Deleted `.cue` files | The modified `.cue` (written by vgmdb-cuefixer) is deleted before restoring the backup |
| Console log | Per-file status messages printed to stdout |

## Usage

1. Open `vgmdb-cuefixer-reverse.py` and set the `root_dir` variable to your music library path:

```python
revert_cue_files(r"C:\MyMusicLibrary")
```

2. Run the script:

```bash
python vgmdb-cuefixer-reverse.py
```

## Examples

```bash
# After editing root_dir in the script:
python vgmdb-cuefixer-reverse.py

# Console output example:
# Deleting modified file: C:\MyMusic\Artist - Album\Album.cue
# Restoring backup: C:\MyMusic\Artist - Album\Album.cue.bak → C:\MyMusic\Artist - Album\Album.cue
```

## Notes

- **Hardcoded path:** The target directory is set inside the script (`revert_cue_files(r"C:\trial")`). Edit this before running.
- The script deletes the existing `.cue` file before restoring the `.bak` — if no `.cue` exists (e.g. it was already manually deleted), the restore still proceeds normally.
- This script only reverts CUE changes; it does not undo any other modifications to the folder.
- If `vgmdb-cuefixer` was run but made no changes (because the CUE was already correct), no `.cue.bak` file will exist, so there is nothing for this script to restore.
- Running this script multiple times is safe — it only acts on files ending in `.cue.bak`.

## Related Scripts

- [vgmdb-cuefixer](vgmdb-cuefixer.md) — The forward operation: fixes CUE `FILE` directives and creates the `.cue.bak` backups this script restores
- [beets-cuemaker](beets-cuemaker.md) — Generate CUE sheets from scratch
