Home > Software engineering >  "IF NOT EXIST" Multiple files?
"IF NOT EXIST" Multiple files?

Time:01-28

i want to make an IF NOT EXIST for some files like

IF NOT EXIST *"%input%*.jpg" && "%input%*.png"* (
ECHO.=========================================
ECHO.=  ERROR : PUT UR IMAGE FILE TO /input  =
ECHO.=========================================
pause
goto MENU
) ELSE (
ECHO.=========================================
ECHO.=             Listing  file             =
ECHO.=========================================
cd %input%
dir /B
ECHO.=========================================
ECHO.=             listing done              =
ECHO.=========================================
timeout /T 2 \> nul
cls

but it says

========================================= 
=  ERROR : PUT UR IMAGE FILE TO /input  =
=========================================

i already put them all png and jpg files but i think i do somenthing wrong :O

CodePudding user response:

If you want to check if both files are present, I would use:

IF EXIST "%input%*.jpg" if exist "%input%*.png" goto :ok
echo at least one of the files is missing.
goto :eof

:ok
echo do something with both files here

The second if is only executed, when the first if finds the first file

CodePudding user response:

@echo off

if exist %1\*.jpg goto :ok
if exist %1\*.png goto :ok
echo no JPG or PNG files found in %1
goto :EOF

:ok
echo found JPG and/or PNG files in %1

If you are looking for files in a subdirectory, you need to remember to use the directory separator (either \ or /) between the directory name and the match pattern.

For testing against multiple different file types, just use multiple ifs.

By the way, you seem to have an extra \ there on the penultimate line, which should read: timeout /t 2 > nul.

  • Related