如何从批处理文件中检查文件是否存在
问题描述:
仅当某个文件存在时,我才需要运行实用程序.如何在 Windows 批处理中执行此操作?
I need to run a utility only if a certain file exists. How do I do this in Windows batch?
答
if exist <insert file name here> (
rem file exists
) else (
rem file doesn't exist
)
或者在一行上(如果只需要执行一个操作):
Or on a single line (if only a single action needs to occur):
if exist <insert file name here> <action>
例如,如果文件存在,这将在 autoexec.bat 上打开记事本:
for example, this opens notepad on autoexec.bat, if the file exists:
if exist c:autoexec.bat notepad c:autoexec.bat