samedi 21 avril 2018

Conditional IF EXIST Statement for multiple filenames in BATCH file

I'm working on the following BATCH script and I'm not sure how I can achieve the results I'm looking for. I searched here as well as online, but I didn't see anything that looked like what I'm looking for. Any help is appreciated.

I need to check if two files exist as well as if they don't. Currently I've got the code below working, however if one file exists or is missing it goes in a 3rd direction. So I need something that works for all 3 cases. I know it's not pretty, but it works and the pretty code doesn't.

Please note that there are other files in the same directory with the same extensions, so searching by extension will not work.

Working Code:

@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
   )
)
:download
echo downloading missing files.
:ok
echo Install successful

What I would like to do:

(The following code isn't expected to work, it's my thoughts written out)

@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

Aucun commentaire:

Enregistrer un commentaire