如何使用批处理文件检查程序的版本



我有一个批处理文件,需要检查它所使用的程序的版本。我相信有更好的方法可以做到这一点,但现在我有一个psuedo循环,它检查是否存在从.8到.0的最新版本的路径。假设程序的正确路径是C:\Apps\ProgramName\5.6,我希望变量ver能存储我需要的值。为什么这个代码不起作用,或者有更好的方法来满足我的需求吗?

set ver=8
:CheckVer
if EXISTS C:AppsProgramName5.%ver% GOTO NextStep
ver=ver-1
if ver LSS 0 GOTO NotFound
GOTO CheckVer

评论中概述的我的解决方案是:

set /a ver=8
:CheckVer
if EXIST C:AppsProgramName5.%ver% GOTO NextStep
set /a ver=%ver%-1
if %ver% LSS 0 GOTO NotFound
GOTO CheckVer
REM FileVer.bat
set filepath=%~f1
set  file=%filepath:=\%
wmic datafile where name^="%file%" get version|findstr /i /v /c:"version"

使用

c:folderfilever.bat c:windowsnotepad.exe

最新更新