@echo off&setlocal enabledelayedexpansion
setlocal enabledelayedexpansion
set strName=curLens_
set strEndChar=_
set /a startPos=86
set /a stopPos=711
set /a startFlag=0
set /a stopFlag=0
set lastRawName=
set lastPos=
md fullsweep_raw
for %%s in (*.raw) do (
set rawName=%%s
set lensPos=!rawName!
::echo !rawName!
call :findStringAndCutDesStr lensPos strName strEndChar
echo lensPos=!lensPos! startPos=!startPos! stopPos=!stopPos!
if not !lensPos!==!lastPos! (
if !startFlag!==1 (
echo record last lens pos !lastPos!
ren !lastRawName! pdaf_input_single_!lastPos!.raw
echo last raw name = !lastRawName!
if !stopFlag!==1 (
goto :stopParse
)
)
)
if !lensPos!==!startPos! (
echo detect start pos !lensPos! ---------------------------
set /a startFlag = 1
)
if !lensPos!==!stopPos! (
if !startFlag!==1 (
echo detect stop pos !lensPos! ---------------------------
set /a stopFlag = 1
)
)
set lastRawName=!rawName!
set lastPos=!lensPos!
)
:stopParse
move pdaf_input_single_*.raw fullsweep_raw
del *.raw
pause
:: 查找指定字符串函数,并截取关键字后,特定字符前的字符串 =====================================================
:: 入参 1 源字符串 入参2 关键字 入参3 结束字符
:findStringAndCutDesStr
::echo findStringAndCutDesStr
set sourStr=!%1!
set findStr=!%2!
set endStr=!%3!
::echo sourStr:!sourStr!
::echo findStr:!findStr!
::echo endStr:!endStr!
set str=!sourStr!
set ch1=%findStr:~0,1%
set /a count=1
:loop
if !count%! EQU 256 (
echo ************* count is equ !count%! end **********************
goto :end
)
if "!str!"=="" (
echo ************* str = null end **********************
goto :end
)
if "!str:~0,1!" == "!ch1!" (
:: 找到第一个字符,确认剩下的字符是否相同 (关键字最大64个字节)
set desStr=!findStr!
for /l %%c in (1 1 32) do (
set str=!str:~1!
set desStr=!desStr:~1!
set tmpCh2=!desStr:~0,1!
set /a count=!count!+1
if "!desStr!"=="" (
goto :findKeyWord
)
if not "!str:~0,1!" == "!tmpCh2!" (
goto :continue
)
)
)
:continue
set str=!str:~1!
set /a count=!count!+1
goto loop:
:: 找到关键字后,截取关键字后,特定字符之前的字符,即目标字符
:findKeyWord
::echo ************ end count = !count! find the key word str=!str! ******************
set tmpStr=!str!
set /a keyWordCount=0
set keyWord=
for /l %%d in (1 1 32) do (
:: echo tmpStr=!tmpStr! endStr=!endStr!
set tmpKeyWordChar=!tmpStr:~0,1!
if "!tmpKeyWordChar!"=="!endStr!" (
goto :KeyWordOK
)
set keyWord=!keyWord!!tmpKeyWordChar!
set /a keyWordCount=!keyWordCount!+1
set tmpStr=!tmpStr:~1!
)
echo Key word error!!
goto :end
:KeyWordOK
::echo ************************ cut the key word : !keyWord! ******************
::set "%~1=%2%"
::set %2=333333
:end
::echo ************ end count = !count! ******************
set %1=!keyWord!
goto:eof
:: 查找指定字符串函数 =====================================================
bat脚本 字符串查找函数和调用, 实现文件批量重命名
最新推荐文章于 2023-07-11 14:00:36 发布