Claude Code for Non-Engineers in Practice · Part 2 · About 10 minutes
100 "Final Version (2)" Filenames: Batch Rename with Claude Code, and Recover If It Goes Wrong
Contents
`Written for: Claude Code 2.1.x (tested on 2.1.311) / October 2026.` Claude Code updates frequently, so screen text, default settings, and command names may change. If your screen differs from this article, `please follow the official documentation.`
What This Article Will Help You Do
Your folder probably contains files like: `Report_Final.docx`, `Report_Final(2).docx`, `Report_Final_edited.docx`, `IMG_20260312_0001.jpg`...
This article shows you how to describe a naming rule in Chinese so Claude Code first generates a rename mapping table for you to review. It only executes after you've confirmed the table, and a one-click undo is prepared before anything is changed. Even if you realize halfway through renaming 100 files that something is wrong, you can restore every file to its original name.
What you'll need:
- Claude Code installed and signed in, following Part 1 (Windows 11 is the main focus; Mac differences are noted separately)
- About 30 minutes
The bottom line: the biggest risk in renaming files isn't making a mistake. It's making a change you can't undo.
Part 1 mentioned a common pitfall. This article addresses it directly:
/rewindonly tracks files that Claude edits with its file editing tools. Renaming files with commands (PowerShell or Bash) is outside its scope, so/rewindwon't restore them. (Per the official Checkpointing documentation)
Batch renames almost always use commands, so you can't rely on `/rewind` for recovery. Use this classic method instead:
`Before renaming, save "old name → new name" as a table (CSV). With that table, undoing is just running the reverse rename.`
This is the core of this article: `Mapping table = execution basis = restore basis.`
Step 1: Create a practice folder with 100 messy filenames
Don't practice on real folders. Open PowerShell, paste the code below (paste it all at once, then press Enter). It creates a 改名練習 (Rename Practice) folder inside Claude練習 (Claude Practice) and fills it with 100 empty files:
$dir = "$env:USERPROFILE\Claude練習\改名練習"
New-Item -ItemType Directory -Force $dir | Out-Null
$names = "報告","企劃書","報價單","會議記錄"
$suffix = "最終版","最終版(2)","最終版_改","final","final_v2","新版"
foreach ($n in $names) { foreach ($s in $suffix) { 1..4 | ForEach-Object { New-Item -ItemType File -Force -Path "$dir\$n`_$s`_$_.txt" | Out-Null } } }
1..4 | ForEach-Object { New-Item -ItemType File -Force -Path "$dir\IMG_20260$_`_0001.jpg" | Out-Null }
(Get-ChildItem $dir).Count
The last line should print `100`. (The author tested this script on Windows 11 PowerShell. Mac users should manually copy a batch of their own files into the folder instead.)
These 100 files are empty and only exist for filename practice. You can use your own files too, but `copy them first and don't use the originals`.
Step 2: Start Claude Code in the practice folder and switch to manual mode
cd "$env:USERPROFILE\Claude練習\改名練習"
claude --permission-mode manual
In `manual` mode, Claude Code asks permission before most file changes and commands (see Part 1, Step 4). The bottom of the screen should show `⏸ manual mode on`.
Step 3: Look first, don't change anything
請先不要修改或改名任何檔案。列出這個資料夾裡的檔案,告訴我目前有哪幾種命名模式(例如「最終版」「final」「IMG_日期」),每種大約有幾個。
This step confirms that Claude Code is looking at the right folder and understands what your filenames look like.
Step 4: Write your naming rules in Chinese
The more specific the rules, the better. Here's a template; adjust it to your needs:
我要整理這個資料夾的檔名,規則如下:
1. 只處理 .txt 和 .jpg,其他檔案不要動。
2. .txt 檔:原檔名格式是「專案名_版本字樣_數字.txt」。請改成「專案名_v編號_流水號.txt」,算法如下:
- 專案名:檔名開頭的「報告」「企劃書」「報價單」「會議記錄」,原樣保留。
- v編號:依版本字樣固定對應——最終版=v1、最終版(2)=v2、最終版_改=v3、final=v4、final_v2=v5、新版=v6。
- 流水號:原檔名結尾的數字 1~4,補成兩位數 01~04。
- 例:「報告_最終版(2)_3.txt」→「報告_v2_03.txt」;「企劃書_final_v2_1.txt」→「企劃書_v5_01.txt」。
3. .jpg 檔:原檔名 IMG_20260X_0001 的格式,改成「照片_2026-0X_0001.jpg」。
4. 不得有兩個檔案改完後同名;若會撞名,在後面加 -a、-b。
5. 不要刪除任何檔案,只能改名。
重要:現在先不要改名。請先產生一份「改名對照表.csv」,兩欄:「舊檔名」「新檔名」,放在上一層資料夾(不要放在改名練習裡面)。CSV 請存成「UTF-8 with BOM」編碼(Windows PowerShell 5.1 和 Excel 才不會把中文欄名讀成亂碼)。存好後停下來等我確認。
Key points:
- `Give examples in your rules.` Saying only "use a consistent format" leaves room for guessing. With one example, it's much less likely to guess wrong.
- `Explicitly state what not to touch.` For example, "Don't change files with other extensions."
- `Keep the mapping table outside the folder.` Otherwise, it will be treated as a file to rename.
- `Don't leave out the final sentence, "Don't rename anything yet." It's the most important sentence in this article.`
Step 5: Review the mapping table (you need to check it yourself)
After Claude Code creates `Rename_Mapping.csv`, open it in Excel or Notepad. It's located one level above `Rename Practice`, in `Claude Practice`. Check four things:
- `Is the count correct?` The number of rows should match the number of files to process (100 rows for this exercise).
- `Are two old names mapped to the same new name?` In Excel, select the "new name" column, then go to Conditional Formatting → Duplicate Values. Highlighted cells mean a name collision.
- `Spot-check 10 rows` to confirm the new names look the way you want.
- `Did it include any files that shouldn't be touched?`
If you're not satisfied, say in Chinese: "Change rule 3 to ..., regenerate the mapping table, and still don't rename anything yet." Repeat until you're happy. At this stage, nothing has been changed, so experiment freely.
Step 6: Prepare the "undo command" first, then execute
This is the critical order: `you need the undo method before you execute.` Next, enter:
對照表我確認過了。請做兩件事,但先不要執行改名:
1. 把這份對照表複製一份,存成「改名對照表_備份.csv」。
2. 寫一個「還原.ps1」放在同一個位置(改名練習的上一層),內容是:用 -Encoding UTF8 讀取對照表,把「新檔名」逐個改回「舊檔名」;如果某個新檔名不存在,就跳過並印出提示,不要報錯中斷。
寫完讓我看過內容,我同意後再執行改名。
When it finishes writing, it will show you the contents of `Undo.ps1`. You don't need to understand every symbol, but you can ask: "Please explain in plain language what this undo file does." A reasonable undo file has simple logic:
# 示意:在「改名練習」資料夾內執行;對照表在上一層,所以用 ..\ 指到它
Import-Csv -Path "..\改名對照表.csv" -Encoding UTF8 | ForEach-Object {
if (Test-Path -LiteralPath $_.新檔名) {
Rename-Item -LiteralPath $_.新檔名 -NewName $_.舊檔名
} else {
Write-Host "找不到 $($_.新檔名),跳過"
}
}
(Note: Before running it, `cd` into the `Rename Practice` folder, since `..\Rename_Mapping.csv` is only found from there. The sample above has `not been tested verbatim`. The concept of "mapping table + reverse rename" is standard practice, but test how Chinese column names and BOM encoding are read. Run it in the practice folder first and confirm the printed count is correct before using it on important files.)
Step 7: Run the rename
Once the backup and undo file are ready, say:
好,請依對照表執行改名。改完後告訴我:成功幾個、失敗幾個、失敗的原因。
Claude Code will ask for your approval step by step. `Just click Yes.` Don't choose options like "switch to auto mode" or "allow for this session" (see Part 1, Step 6 for why).
After it's done, check with `Get-ChildItem` or File Explorer, and compare the results with the numbers Claude Code reported.
Step 8: What to do if something goes wrong (three levels)
`Level 1: Nothing has been changed yet; only the mapping table is wrong.` Ask Claude Code to regenerate the mapping table. Nothing was touched, so there's no loss.
`Level 2: Everything was renamed, and you want to revert it all.` In Claude Code, say:
請執行「還原.ps1」,把檔名全部改回改名前的狀態,完成後告訴我有幾個檔案還原成功、幾個被跳過。
Or, without Claude, open PowerShell, navigate to the folder, and run the `.ps1` file. This is when the undo file proves its value: `even if Claude Code crashes or you close the window, the file is still there.`
If PowerShell says "Running scripts is disabled on this system," Windows' default execution policy is blocking it. You can ask Claude to rewrite the restore steps as a command you paste directly into PowerShell, or see Microsoft's ExecutionPolicy documentation. (The author has not tested this case, so it is marked "to be verified.")
`Level 3: Interrupted halfway, or only some files were renamed.` This is what the "skip files not found" rule is for. The undo file can safely run repeatedly, and files already back to their old names won't be affected.
`Final safeguard:` For truly important folders, `make a full copy before you start.` A mapping table can save filenames, but it can't save files you accidentally tell Claude Code to delete.
Step 9: Save these rules for next time, so one sentence is enough
Once you're happy with the rules, ask Claude Code to write them into `CLAUDE.md`:
請把我們這次的命名規則,還有「改名一定要先產生對照表並等我確認、並備好還原檔才能執行」這個流程,寫進這個資料夾的 CLAUDE.md。
The next time you start Claude Code in the same folder, just say "organize new files by the rules," and it will generate a mapping table first, following your established process. (We'll cover how to write CLAUDE.md in a future article.)
Three "don'ts"
- `Don't skip the mapping table and say "just rename everything."` With 100 files, you'll hardly ever catch the mistakes by eye afterward.
- `Don't batch-rename in cloud-synced folders (Google Drive, OneDrive) or shared drives.` The sync client may start uploading or creating conflicts while you're mid-rename.
- `Don't use an old undo file after the mapping table has changed.` The undo file and mapping table are a pair. If you change one, regenerate both.
Next episode preview
Part 3: `"Teaching It Your Habits: How to Write CLAUDE.md for Non-Engineers"` covers what to include and exclude in CLAUDE.md, and how to confirm Claude Code is actually reading it.
Want a template you can use right away?
References (all official documentation, accessed 2026-10)
- Checkpointing (what `
/rewind` tracks and its limits): https://code.claude.com/docs/zh-TW/checkpointing - Choose a permission mode: https://code.claude.com/docs/zh-TW/permission-modes
- Remember your project (CLAUDE.md): https://code.claude.com/docs/zh-TW/memory
- Documentation home: https://code.claude.com/docs/zh-TW
Notes: The author tested the generation command in Step 1 on Windows 11 PowerShell 5.1. The undo example in Step 6 (paths, BOM/UTF-8 reading) is `untested`. Claude Code's actual conversation screens and the undo file it generates vary by version and response, and `have not been tested verbatim`. Follow what you see on your screen. Mac commands are untested.
Related Series Reading
- Using Claude Code Without Writing Code: Your First Automation Task, Tidying a Messy Downloads Folder
- Turn Your Weekly Tasks into a Skill Card: An Introduction to Agent Skills (Meeting Notes and Invoice Filing)
`← Back to article listNext: Teaching It Your Habits: How to Write CLAUDE.md for Non-Engineers →`