标题: [文件操作] for中用SET设置变量后不生效,第2次执行才生效 [打印本页]
作者: keetian 时间: 2015-2-7 12:24 标题: for中用SET设置变量后不生效,第2次执行才生效
@echo off
set "wmpfile=C:\Program Files\Windows Media Player\wmplayer.exe"
if not exist "%wmpfile%" (
echo 未安装Windows Media Player 11...
)
if exist "%wmpfile%" (
for /f "tokens=5" %%i in ('filever.exe "%wmpfile%"') do SET wmpver=%%i
echo 已安装Windows Media Player "%wmpver%"
)
以上代码存为f.bat,在cmd窗口中,第一次执行f.bat,输出已安装Windows Media Player ""
第一次执行f.bat,输出已安装Windows Media Player "10.0.0.3802"
请问怎么解决呢?
作者: pcl_test 时间: 2015-2-7 12:41
回复 1# keetian - @echo off
- setlocal enabledelayedexpansion
- set "wmpfile=C:\Program Files\Windows Media Player\wmplayer.exe"
- if not exist "%wmpfile%" (
- echo 未安装Windows Media Player ...
- ) else (
- for /f "tokens=5" %%i in ('filever.exe "%wmpfile%"') do SET wmpver=%%i
- echo 已安装Windows Media Player !wmpver!
- )
- pause
复制代码
作者: DAIC 时间: 2015-2-7 14:23
- @echo off
- setlocal enabledelayedexpansion
- set "wmpfile=C:\Program Files\Windows Media Player\wmplayer.exe"
- if not exist "%wmpfile%" (
- echo 未安装Windows Media Player ...
- ) else (
- for /f "tokens=5" %%i in ('filever.exe "%wmpfile%"') do (
- set "wmpver=%%i"
- )
- echo 已安装Windows Media Player !wmpver!
- )
- pause
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |