我正在尝试使用.cmd比较两个文件以进行更改。现在,我只需要找一个比较小的字符串而不是整个文件。
这些信息紧接在这些文件中的“更改号码:”之后。如下:
Steam Console Client (c) Valve Corporation
-- type 'quit' to exit --
Loading Steam API...OK.
AppID : 346110, change number : 1230200/1230201, token 0, last change : Wed Aug 19 08:36:34 2015
"346110"
在这种情况下,结果应为“1230200/1230201”
以下是我尝试使用的代码。
rem Because its SteamCMD we only want to check change numbers as other parts of the file change frequently
for /f "tokens=3 delims=:/" %%a in ('find "change number :" ^< %~n0-latest-version ') do SET "latest=%%a"
for /f "tokens=3 delims=:/" %%a in ('find "change number :" ^< %~n0-current-version ') do SET "current=%%a"
IF NOT %latest% == %current% goto shutdown_server
当IF NOT %latest% == %current%
行运行时,%latest%和%current%中没有存储任何信息。
我相信我的代码中存在某种语法错误,但我只是看不到它。有什么建议?
答案 0 :(得分:0)
如果将'/'指定为分隔符,则不会使用第一个数字拾取第二个数字。这是非常硬编码的。
C:>type f-current-version
team API...OK.
AppID : 346110, change number : 1230200/1230201, token 0, last change : Wed Aug 19 08:36:34 2015
"346110"
C:>type f-latest-version
team API...OK.
AppID : 346110, change number : 1230200/1230201, token 0, last change : Wed Aug 19 08:36:34 2015
"346110"
cmd脚本
for /f "tokens=5 delims=:, " %%a in ('find "change number :" ^< %~n0-latest-version ') do SET "latest=%%a"
for /f "tokens=5 delims=:, " %%a in ('find "change number :" ^< %~n0-current-version ') do SET "current=%%a"
echo %latest%
echo %current%
C:>f.bat
1230200/1230201
1230200/1230201