方法1- @echo off&setlocal enabledelayedexpansion
- for /f "tokens=1,*delims=_" %%1 in (1.txt)do (
- set col=0
- set old_name=%%1_%%2
- set str=%%2#
- for /l %%3 in (1,1,20)do (
- call set mid=%%str:~%%3,1%%
- set /a col+=1
- if !mid!==_ (
- set /a b=!col!
- )
- )
- call set new_name=%%str:~,!b!%%
- ren !old_name! !new_name!
- )
复制代码 方法2- @echo off&powershell -nologo -executionpolicy bypass "gc 1.txt|%%{ren $_ ([regex]::Matches($_,'(?<=.+_).+(?=_.+)').value) -ErrorAction Ignore}"
复制代码
|