Windows 技巧 · Windows Tips
Windows 合并 PDF:文件顺序与批量命名 / Windows PDF Merge: Getting the File Order Right
Windows 上合并 PDF 最常见的翻车不在工具,而在顺序。资源管理器按文本排序,1/10/2 会把整份文件排乱。这篇给出改名、显式排序两种解法,以及发出去之前的三步核对。
阅读约 6 分钟 · 6 min read
为什么 Windows 会这样排
资源管理器用的是语言学排序,不是数值排序。逐字符比较时 1 排在 2 前面,所以 10 夹在 1 和 2 之间。这不是 bug,也不会变。解法是改名,而不是反复点排序。
先补零,最省事
让所有文件名长度一致,任何排序规则下都不会错:scan-001.pdf 到 scan-020.pdf。PowerShell 里一行搞定:
Get-ChildItem *.pdf | Sort-Object { [int]($_.BaseName -replace '[^0-9]','') } | ForEach-Object -Begin { $i = 1 } -Process { Rename-Item $_ ("scan-{0:D3}.pdf" -f $i); $i++ }
在扫描件所在的文件夹里运行。它先读出每个名字里已有的数字并按数字排序,然后统一改成三位补零的名字。
或者显式指定顺序
不能改名的时候(共享文件夹、别处已经引用了这些名字),就把顺序直接交给工具。PDFsam Basic 可以在导出前拖动行调整位置。命令行里 qpdf 按你写进去的顺序取页:qpdf --empty --pages 01.pdf 02.pdf 03.pdf -- out.pdf。浏览器里,PDFMergeNext 在拖入文件之后可以拖动重排,缩略图会先显示当前顺序,确认过再跑。
发出去之前核对三处
- 打开合并结果,跳到每一节的第一页。十秒钟,能抓出大部分顺序错误。
- 对页数。查看器里的页码应该等于各输入之和。
- 有封面的那一节,确认封面真的在第一页。顺序错通常出现在节的边界上,而不是中间。
整文件夹批量合并
50 个以上文件时别一个个选。先把名字补零,全选,一次拖进去。浏览器工具按系统交过来的顺序读取,所以补零依然是关键。总输入超过 500MB 时注意内存。
哪些顺序能保住
| 来源 | 顺序正确吗 | 说明 |
|---|---|---|
| 补零后全选 | 正确 | 最稳的做法 |
| 未补零直接全选 | 错误 | 会变成 1、10、2、20 |
| 在工具里拖动重排 | 正确 | 顺带做一次目视检查,值得 |
| 命令行显式列出 | 正确 | 顺序就是你打进去的顺序 |
| 只给文件夹路径 | 看工具 | 自己扫目录的工具会继承资源管理器的顺序 |
规律是:名字决定顺序,工具只是照做。把名字修好,剩下的基本不会错。
English version
Why Windows sorts it that way
Explorer uses a linguistic sort rather than a numeric one. Compared character by character, 1 sits before 2, so 10 lands between them. That is not a bug and it is not going to change. Renaming is the fix, not clicking the sort header again.
Zero-pad the names first
Make every name the same length and no sort rule can get it wrong: scan-001.pdf through scan-020.pdf. One line of PowerShell does it:
Get-ChildItem *.pdf | Sort-Object { [int]($_.BaseName -replace '[^0-9]','') } | ForEach-Object -Begin { $i = 1 } -Process { Rename-Item $_ ("scan-{0:D3}.pdf" -f $i); $i++ }
Run it in the folder holding the scans. It reads the number already in each name, sorts on that number, then renames everything to a three-digit form.
Or pass the order explicitly
When renaming is not an option, because the folder is shared or something else points at those names, hand the order to the tool. PDFsam Basic lets you drag rows into position before export. On the command line, qpdf takes pages in the order you list them: qpdf --empty --pages 01.pdf 02.pdf 03.pdf -- out.pdf. In the browser, PDFMergeNext reorders by drag after the files land, and the thumbnail strip shows the current sequence before you run anything.
Three checks before you send it
- Open the result and jump to the first page of each section. Ten seconds, and it catches most order mistakes.
- Compare page counts. The number in your viewer should equal the sum of the inputs.
- If one section has a cover page, confirm it is actually first. Order errors show up at boundaries, not in the middle.
Batch merging a whole folder
With 50 files or more, do not pick them one at a time. Pad the names, select all, and drop them in a single action. Browser tools read files in the order the system hands them over, so padded names still matter. Watch memory once the total input passes about 500MB.
Which orders survive
| Source | Order kept? | Notes |
|---|---|---|
| Zero-padded names, select all | Yes | The reliable option |
| Unpadded names, select all | No | Becomes 1, 10, 2, 20 |
| Drag to reorder in the tool | Yes | Worth doing anyway as a visual check |
| Command line with an explicit list | Yes | The order is whatever you type |
| Folder path only | Depends | Tools that scan the directory inherit Explorer order |
The pattern: names decide the order and the tool just follows. Fix the names and most of the problem disappears.
To merge without installing anything, the home page runs the job in your browser. For the other two systems, see the Linux guide and the Mac guide.
立即合并
在浏览器本地完成合并,文件不离开你的设备。
打开 PDFMergeNext →常见问题
Why did my merged PDF come out as 1, 10, 2?
Explorer sorts file names as text, not as numbers. Rename the files with leading zeros, or reorder them inside the tool before you export.
Can I merge a whole folder on Windows without installing anything?
Yes. Pad the names so they sort correctly, select all, then drop the files into a browser tool like PDFMergeNext. The merge runs on your machine.
Does renaming the files break anything?
Only references to the old names. If something else points at those files, pass an explicit order to the merger instead of renaming.
How do I merge 100 files at once on Windows?
Pad every name to a fixed width, select all, and merge in one run. Above roughly 500MB of total input, watch memory usage.