You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

批量重命名RAR分卷文件并保留分卷编号的技术问询

Solution for Batch Rename of RAR Split Files

To achieve your desired renaming pattern—replacing the original prefix while preserving the numeric suffix and split identifier—here's the adjusted batch script with step-by-step explanations:

Adjusted Batch Code

SETLOCAL EnableDelayedExpansion
REM Set your target directory here
CD "D:\test\rename"

FOR /F "usebackq tokens=* delims=" %%A IN (`DIR "*.rar" /B /A:-D`) DO (
    REM Extract the filename without the .rar extension (e.g., "File-01.part1")
    SET "FullNameNoExt=%%~nA"
    
    REM Split the name into two parts using the dot before "part" as the delimiter
    FOR /F "tokens=1,2 delims=." %%B IN ("!FullNameNoExt!") DO (
        REM %%B = original base name (e.g., "File-01"), %%C = split identifier (e.g., "part1")
        
        REM Extract the numeric portion from the original base name (everything after the hyphen)
        SET "OriginalBase=%%B"
        SET "NumericSuffix=!OriginalBase:*=-!"
        
        REM Construct the new filename and rename the file
        RENAME "%%A" "Newfile__!NumericSuffix!.%%C%%~xA"
    )
)
ENDLOCAL

Key Changes & Explanations

  • Splitting the Filename: We first split the filename (excluding the .rar extension) into two parts using the dot before part as a delimiter. This separates the original base name (like File-01) from the split identifier (like part1).
  • Extracting the Numeric Suffix: Using batch variable substitution !OriginalBase:*=-!, we capture everything after the first hyphen in the original base name. This pulls out the 01 from File-01 cleanly.
  • Building the New Name: We combine your fixed prefix Newfile__, the extracted numeric suffix, the split identifier, and the original .rar extension to form the exact target filename you want.

Notes

  • If your original base names use a different separator (not a hyphen), adjust the substitution pattern. For example, if the original was File_01.part1.rar, change !OriginalBase:*=-! to !OriginalBase:*=_!.
  • Always test the script on a copy of your files first to confirm it behaves as expected.
  • The script only processes .rar files in the specified directory and ignores subdirectories.

内容的提问来源于stack exchange,提问作者Hung PD

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 09:52:03