forfiles /p c:\ /m *.xlsx /d 0 2>nul && call Success.bat || call Fail.bat
2>nul
will suppress error messages, you can also add >nul
to suppress standard output (any files found by forfiles
). If no files exist with the extension then an errorlevel will be set - the commands following ||
will only occur if an error level is set.
Therefore, if no files are found with the specified extension this will call Fail.bat
, and goto the end of the script. If files are found, it will call Success.bat
.