PD_Name_ReplaceWordOrder
Moving a keyword to the front (or back) of your filenames, in bulk
- show
If you've ever stared at a folder of captioned training images and wished every file with "cat" in the name had it first instead of buried in the middle, this is the node. It scans a directory and rewrites filenames so a keyword you pick moves to the front - or the back - of the name, and it leaves everything else alone. It's a rename utility, pure and simple, the kind of thing you'd otherwise script with a couple lines of Python and then immediately worry you got wrong.
Let's be honest about the scope: it's a thin node. One folder, one keyword, one position swap. But it's the rare case where having it inside ComfyUI is genuinely handy, because it sits next to the rest of the PDuse file-tools and its report comes back as a string you can read right in the graph - no console archaeology.
How it works
You give it a directory_path, a file_format (jpg / png / mp3 / txt / all), a search_keyword, and a wordorder (front or end). It lists the matching files, and for every one whose stem contains the keyword it pulls the keyword out and re-glues it at the chosen position. The extension is preserved; the rest of the name keeps its original order and symbols - the keyword is removed and re-inserted, not the whole name shuffled.
A few behaviors worth knowing, straight from the source:
- If the keyword is already in the right place, the file is skipped (reported as "already in position").
- If the target filename already exists, the rename is skipped, not overwritten. No silent clobbering - good.
- When
wordorder = endand the name is exactly the keyword, nothing changes. file_format = "all"grabs every file in the folder (non-recursive).
The inputs that matter
directory_path- absolute path to the folder. Windows-style backslashes are normalized for you.search_keyword- the token to relocate. Empty string is an error, reported in the output.wordorder-frontorend. That's the whole decision.
The single output, show, is a formatted report: directory, format, total files, how many were modified, and a per-file log with ✅/⚪/⚠️/❌ markers.
Installing it
It's part of Comfyui_PDuse by 7BEII - same install as every node in this pack. ComfyUI Manager (search "PDuse") or:
cd ComfyUI/custom_nodes
git clone https://github.com/7BEII/Comfyui_PDuse.git
cd Comfyui_PDuse
pip install -r requirements.txt
Restart ComfyUI. No model downloads; the dependencies are the pack's usual numpy, Pillow, scipy, opencv-python, torchvision. Documentation is Chinese-first (Feishu wiki + Bilibili), so the tooltips and this writeup may be the most English you get.
Where people get burned
This one modifies real files on disk, with no undo and no recycle bin. If you point it at a folder you care about, test on a copy first - that advice applies to every file-tool in this pack, but especially the renamers. And note there's no separator injected: mycat_image.jpg with keyword "cat" moved to the front becomes catmy_image.jpg, not cat_my_image.jpg. If you need a clean _ boundary, rename with an explicit separator upstream or pick a keyword that carries one.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| directory_path | STRING | C:\\path\\to\\your\\files | — |
| file_format | COMBO | txt | 5 options: jpg, png, mp3, txt, all |
| search_keyword | STRING | — | |
| wordorder | COMBO | front | 2 options: front, end |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| show | STRING | — |