批处理 判断文件是否存在

2025-02-03 18:12:26
推荐回答(5个)
回答1:

批处理判断文件是否存在可以参考以下的代码:

@echo off

if exist c:\a.exe (start a.exe) else echo 文件不存在.

pause

判断系统安装路径下的a.exe,同理:(%windir%代表系统目录)

if exist "%windir%\system32\a.exe" (start %windir%\system32\a.exe) else echo 文件夹不存在

扩展资料:

命令简介

echo 命令

打开回显或关闭请求回显功能,或显示消息。如果没有任何参数,echo

命令将显示当前回显设置。

语法

echo [{on|off}] [message]

Sample:@echo off / echo hello world

在实际应用中我们会把这条命令和重定向符号(也称为管道符号,一般用> >> ^)结合来实现输入一些命令到特定的文件中。

参考资料来源:百度百科-批处理

回答2:

@echo off
if exist 路径\a.*** goto exit
b.***
:exit
说明:
(1) IF EXIST 是用来测试文件是否存在的,格式为
IF EXIST [路径+文件名] 命令

回答3:

@echo off
if exist c:\a.exe (start a.exe) else echo 文件不存在.
pause

PS:判断系统安装路径下的a.exe,同理:(%windir%代表系统目录)

if exist "%windir%\system32\a.exe" (start %windir%\system32\a.exe) else echo 文件夹不存在

回答4:

::如文件路径是c:\a.exe就直接用这命令就行了.
@echo off
if exist c:\a.exe (start a.exe) else echo 文件不存在
::如是在C盘不知那个目录的话就用这命令吧
@echo off
for /f "delims=" %%i in ('dir /b/s c:\a.exe')do start "" "%%i"

回答5:

@echo off
if not exist C:\a.exe goto nofile
echo a.exe存在
pause
exit
:nofile
echo a.exe不存在
pause