batch小计:重新生成文本类文件每行出现多余空格

:: Read the file line by line
for /f "tokens=* delims=" %%a in ('findstr /n "^""%filePath%"') do (
    set "line=%%a"
    set "line=!line:*:=!"
    if "!line!"=="" (
        echo. >> "%tmpFile%"
    ) else (
        echo !line! >> "%tmpFile%"
        if "!line!"=="%section%" (
            echo %lineToAdd% >> "%tmpFile%"
            set "found=1"
        )
    )
)

在批处理文件中,当使用 echo 命令和重定向符号 >> 时,如果命令和重定向符号之间有空格,那么这个空格会被写入到文件中。为了避免这种情况,确保 echo 命令的字符串直接跟随重定向符号,中间没有空格。

:: Read the file line by line
for /f "tokens=* delims=" %%a in ('findstr /n "^" "%filePath%"') do (
    set "line=%%a"
    set "line=!line:*:=!"
    if "!line!"=="" (
        (echo()>>"%tmpFile%"
    ) else (
        (echo(!line!)>>"!tmpFile!"
        if "!line!"=="%section%" (
            (echo(%lineToAdd%)>>"%tmpFile%"
            set "found=1"
        )
    )
)

你可能感兴趣的:(UE)