批量移动后缀序号/随机ID(图片、JPEG、RAW等文件适用)
Got it, let's sort out this batch file renaming task for your images. I'll cover command-line solutions (perfect for large batches) and a GUI option if you prefer clicking over typing.
Windows (PowerShell)
PowerShell comes built-in with Windows, so no extra software needed. Here's how to do it:
- Open PowerShell and navigate to your image folder (use
cd C:\Path\To\Your\Images). - Run this command to preview changes first (add
-WhatIfto avoid actually renaming):
Get-ChildItem -Filter "*.jpg","*.raw","*.png" | Rename-Item -NewName { $_.Name -replace '^(.*)_©_Hello_World_([A-Za-z0-9]+)\.([a-zA-Z0-9]+)$', '$1_$2_©_Hello_World.$3' } -WhatIf
- If the preview looks correct, remove
-WhatIfto apply the renaming.
Breakdown:
Get-ChildItemgrabs all files matching your specified formats (add more like*.tifif needed).- The regex
^(.*)_©_Hello_World_([A-Za-z0-9]+)\.([a-zA-Z0-9]+)$captures three parts:$1: The main prefix of the filename (e.g.,Australia_Brisbane_NP)$2: The random ID/number at the end (e.g.,1163,AHDFGF)$3: The file extension (e.g.,jpg,raw)
- We rearrange these parts into the desired format:
$1_$2_©_Hello_World.$3
macOS/Linux (Bash)
Most Unix-like systems use the rename command (note: Debian/Ubuntu uses prename, which is Perl-based, while macOS uses a simpler built-in version—both work here):
- Open Terminal and navigate to your image folder (
cd /Path/To/Your/Images). - Preview changes first by running:
# Debian/Ubuntu prename -n 's/^(.*)_©_Hello_World_([A-Za-z0-9]+)\.([a-zA-Z0-9]+)$/$1_$2_©_Hello_World.$3/' *.{jpg,raw,png} # macOS rename -n 's/^(.*)_©_Hello_World_([A-Za-z0-9]+)\.([a-zA-Z0-9]+)$/$1_$2_©_Hello_World.$3/' *.{jpg,raw,png}
- Remove the
-nflag to apply the renaming once you're happy with the preview.
Breakdown:
- The
*.{jpg,raw,png}glob matches all files with those extensions (add more as needed). - The regex substitution works exactly like the PowerShell version—capturing the three parts and rearranging them.
GUI Alternative (Cross-Platform)
If you'd rather use a visual tool, XnConvert (free, cross-platform) is great for batch renaming with regex:
- Download and open XnConvert.
- Click "Add files" or drag-and-drop all your images into the app.
- Go to the Actions tab, then click "Add action" > "Rename".
- In the "Rename" settings:
- Set "Method" to "Regular expression".
- In "Pattern", enter:
^(.*)_©_Hello_World_([A-Za-z0-9]+)\.([a-zA-Z0-9]+)$ - In "Replace with", enter:
$1_$2_©_Hello_World.$3
- Click "Preview" to check the new filenames, then click "Convert" to apply the changes.
Pro Tip:
Always preview changes first! Command-line tools have preview flags (-WhatIf in PowerShell, -n in rename), and GUI tools let you check before applying—this avoids accidental mistakes with your files.
内容的提问来源于stack exchange,提问作者Emmanuel

