首页 > 解决方案 > 获取一个批处理文件,告诉我 csv 文件中有多少行

问题描述

我有一个用于蟾蜍自动化的批处理文件。批处理文件应该足够简单,但由于某种原因它不喜欢 if 雕像我什至尝试了 GTR 示例,但遗憾的是,我在 if 语句中得到的只是语法不正确并且不知道为什么。

    @Echo off
    Set _File=ExportDiffFile.csv
    Set /a _Lines=0
    For /f %%j in ('Find "" /v /c ^< %_File%') Do Set /a _Lines=%%j
    REM Echo %_File% has %_Lines% lines.

    if "%_Lines%"=="1"(
        Echo %_File% has no new lines.
        Echo 100.
        REM exit 100
    )
    else
    (
        Echo %_File% has %_Lines% new lines.
        Echo adding into the server.
        REM exit 0
    )

标签: batch-fileif-statement

解决方案


看来我没有正确设置它。

这就是它应该的样子。把问题留在这里,以防有人需要。

    @Echo off
    Set _File=ExportDiffFile.csv
    Set /a _Lines=0
    For /f %%j in ('Find "" /v /c ^< %_File%') Do Set /a _Lines=%%j
    Echo %_File% has %_Lines% lines.


    IF "%_Lines%" EQU "1" (
        Echo %_File% has no new lines.
        Echo 100.
        REM exit 100
    ) ELSE (
        Echo %_File% has %_Lines% new lines.
        Echo adding into the server.
        REM exit 0
    )

推荐阅读