我正在处理以下批处理脚本,但我不确定如何实现我所需要的结果。我在这里和网上搜索过,但没有看到像我需要的内容。非常感谢你的帮助。
我需要检查两个文件是否存在,以及它们是否不存在。目前我有下面的代码可以工作,但是如果一个文件存在或者缺失了,它会进入第三种情况(我已经更新了代码以解决第三种情况,现在它可以正常工作了,但我知道还有很多改进的空间!)。我知道它不太好看,但它能工作,而且漂亮的代码可能并不行得通。
请注意,同一目录下有其他具有相同扩展名的文件,因此按扩展名搜索将无效。
工作代码:
我需要检查两个文件是否存在,以及它们是否不存在。目前我有下面的代码可以工作,但是如果一个文件存在或者缺失了,它会进入第三种情况(我已经更新了代码以解决第三种情况,现在它可以正常工作了,但我知道还有很多改进的空间!)。我知道它不太好看,但它能工作,而且漂亮的代码可能并不行得通。
请注意,同一目录下有其他具有相同扩展名的文件,因此按扩展名搜索将无效。
工作代码:
@echo off
echo checking file structure...
if exist "file1.exe" (
if exist "file2.zip" (
goto ok
)
)
if not exist "file1.exe" (
if not exist "file2.zip" (
goto download
)
)
if not exist "file1.exe" (
goto download
)
)
if not exist "file2.zip" (
goto download
)
)
:download
echo downloading missing files.
:ok
echo Install successful
我想要做的事情:
(以下代码不会起作用,只是我的思路记录)
@echo off
set file1=setup.exe
set file2=package.zip
if exist $file1 && $file2 then goto ok
else if not exist $file1 || $file2 goto download
为什么仅检查这两个文件是不够的示例
在IT技术方面。echo checking file structure...
if exist "setup.exe" if exist "package.zip" goto TEST1
if not exist "setup.exe" if not exist "package.zip" goto TEST2
ECHO [Error!] - 1 File is present, the other is missing!
PAUSE
:TEST1
ECHO [Success!] - Found both files, YAY!
PAUSE
:TEST2
ECHO [Error!] - No matching files found.
PAUSE