中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-06-17 04:42
中国DOS联盟论坛 » DOS疑难解答 & 问题讨论 (解答室) » 请问一个关于批处理文件的IF EXIST指令的问题 查看 1,860 回复 2
楼 主 请问一个关于批处理文件的IF EXIST指令的问题 发表于 2005-09-06 23:43 ·  中国 广东 潮州 电信
新手上路
积分 3
发帖 1
注册 2005-09-06 23:41
UID 42306
性别 男
来自 ca
状态 离线
请问IF EXIST可不可以同时检查两个文件是否存在?

[ Last edited by houston1984 on 2005-9-6 at 23:45 ]
2 发表于 2005-09-07 00:28 ·  中国 北京 大兴区 联通
初级用户
★★
积分 185
发帖 82
注册 2005-08-12 13:41
UID 41586
性别 男
状态 离线
假如你要检测两个文件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 ]
3 发表于 2005-09-07 07:31 ·  中国 山西 运城 中移铁通
元老会员
★★★★
Batchinger
积分 4,432
发帖 1,512
注册 2002-10-18 00:00
UID 19
性别 男
状态 离线
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 文件不都存在)
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
论坛跳转: