Board logo

标题: 请问一个关于批处理文件的IF EXIST指令的问题 [打印本页]

作者: houston1984     时间: 2005-9-6 23:43    标题: 请问一个关于批处理文件的IF EXIST指令的问题
请问IF EXIST可不可以同时检查两个文件是否存在?

Last edited by houston1984 on 2005-9-6 at 23:45 ]

作者: floor     时间: 2005-9-7 00:28
假如你要检测两个文件a.txt、b.txt

rem 检查a.txt
:check_a
if exist a.txt goto check_b
goto fault

rem 检查b.txt
:check_b
if exist b.txt goto success
goto fault

:success
echo 两个文件都存在
goto exit

:fault
echo 至少有一个文件不存在

:exit

Last edited by floor on 2005-9-7 at 00:30 ]

作者: willsort     时间: 2005-9-7 07:31
Re houston1984:


if exist a.txt if exist b.txt set _filexist=true
if "%_fileexist%"=="true" echo 文件都存在
if not "%_fileexist%"=="true" echo 文件不都存在
set _fileexist=

或者

if not exist a.txt echo 不存在a.txt
if not exist b.txt echo 不存在b.txt
if exist a.txt if exist b.txt echo 文件都存在

或者

if exist a.txt if exist b.txt goto filexist
echo 文件不都存在
goto end

:filexist
echo 文件都存在
:end

或者(只在WinNT系列的CMD下有效)

if exist a.txt if exist b.txt (echo 文件都存在) else (echo 文件不都存在)