本帖最后由 yhcfsr 于 2018-1-11 14:04 编辑
- @echo off
- set "ScDir=D:\temp"
- set "spt1=#EXTINF:"
- set "spt2=,"
- cd /d "%ScDir%"
- for /f "delims=" %%a in ('dir /a-d /s /b *.txt') do (
- for /f "delims=" %%i in ('findstr /n ".*" "%%a"') do (
- set "var=%%i"
- setlocal enabledelayedexpansion
- set var=!var:*:=!
- echo;!var!|findstr "%spt1%">nul
- if !errorlevel!==0 (
- rem 提取尾部字符串
- call :get_string "!var!" end_str
- rem 生成新的字符串
- set "var=%spt1%-1 %spt2%!end_str!"
- echo !var!
- ) else if !var!. neq . (echo !var!) else (echo.)
- endlocal
- )>>"%%a.log"
- rem 删除move前rem可对源文件进行替换
- rem move /y "%%a.log" "%%a">nul
- )
- pause
- exit
- rem 获取,后结尾字符串
- :get_string
- setlocal
- set "name=%~1"
- :lp
- call set "ch=%%name:~%i%,1%%"
- if "%ch%" neq "%spt2%" set /a i-=1&goto :lp
- set /a i+=1
- call set "name=%%name:~%i%%%"
- endlocal&set "%2=%name%"&goto:eof
复制代码
|