I'm facing an issue when trying to implement the ERRORLEVEL
on my batch script. Basically what I'm trying to do is: look for the .txt
files in the directory and if found; .txt
will get listed, if not found; message error will occur.
The thing is that this directory will not always contain a .txt
, sometimes it will be empty and when that happens my code will not work. Only when there is a .txt
in the directory I'm getting my conditions to work (ERRORLEVEL = 0
), but if empty; none of my conditions will. Not even the ERRORLEVEL
will be printed in the cmd screen (I should see it as ERRORLEVEL = 1
).
This is my code:
for /r "C:\Texts" %%a in (*.txt) do (
echo %errorlevel%
IF ERRORLEVEL 0 (
echo %%a
echo "I found your Text!"
) ELSE (
echo "I couldn`t find your Text!" )
)
What exactly is wrong with my ERRORLEVEL
implementation?