本帖最后由 aloha20200628 于 2024-6-3 20:57 编辑
回复 12# dzwind
删除文本行头部英文?字符不能直接加入5楼代码第9行,因为 for %%a in (...) 表达式中的?和*会被cmd视为通配符处理,故须改用别法解决...
新代码如下》其中第11行代码排列了文本行头部可能要被删除的多种字符,如中英文空格和制表符以及英文?字符...
- @echo off &setlocal enabledelayedexpansion
- for /f "delims=" %%F in ('dir/s/b/a-d *.txt') do (
- set/a "pm=1,qm=1"
- (for /f "usebackq delims=" %%a in ("%%~F") do (
- set "s=%%a"&set "s=!s:......=…!"&set "_s=!s!"
- for %%n in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
- if "!_s:~%%n,1!" neq "" (set/a "ls+=%%n"&set "_s=!_s:~%%n!")
- )
- for /L %%n in (1,1,!ls!) do (
- set "c=!s:~,1!" &set "x=0"
- if "!c!" neq " " if "!c!" neq " " if "!c!" neq " " if "!c!" neq "?" (set "x=1")
- if !x! equ 0 (set "s=!s:~1!"&set/a "ls-=1")
- )
- for /L %%n in (0,1,!ls!) do (
- set "c=!s:~%%n,1!" & if ^!c! == ^" (
- set/a "pm=0-!pm!" &if !pm! equ -1 (set "c=“") else (set "c=”")
- ) else if "!c!" == "'" (set/a "qm=0-!qm!" &if !qm! equ -1 (set "c=‘") else (set "c=’"))
- set "_line=!_line!!c!"
- )
- echo,!_line!&set "_line="&set "ls=0"
- ))>"%%~F.new"
- )
- endlocal&exit/b
复制代码
|