I have an old script that does a number of things, renaming some files. But there error is that if there are no files, it just continues. So I added a hop that is followed on 'result false', and that is executed when there are no files there. This is the script, the first four lines are added by me:
IF NOT EXIST "${DATA_DIR}\*.*" (
ECHO NO FILES DOWNLOADED, ABORTING
ABORT
) ELSE (
IF EXIST "${DATA_DIR}\Bel_Main*.txt" (
RENAME "${DATA_DIR}\Bel_Main*.txt" Bel_Main.txt
)
IF EXIST "${DATA_DIR}\ParcomBE*.txt" (
RENAME "${DATA_DIR}\ParcomBE*.txt" ParcomBE.txt
)
IF EXIST "${DATA_DIR}\BalansBE*.txt" (
RENAME "${DATA_DIR}\BalansBE*.txt" BalansBE.txt
)
)
However, it seems to follow the 'abort path', just because it does not recognize the command 'ABORT'. This is the output:
2022/08/10 17:21:11 - rename files - (stdout) )
2022/08/10 17:21:11 - rename files - (stdout) NO FILES DOWNLOADED, ABORTING
2022/08/10 17:21:11 - rename files - ERROR (version 7.1-SNAPSHOT, build 1 from 2017-08-23 17.37.41 by olbicoserviceuser) : (stderr) 'ABORT' is not recognized as an internal or external command,
2022/08/10 17:21:11 - rename files - ERROR (version 7.1-SNAPSHOT, build 1 from 2017-08-23 17.37.41 by olbicoserviceuser) : (stderr) operable program or batch file.
2022/08/10 17:21:11 - DnB Data Preparation - Starting entry [Abort job]
2022/08/10 17:21:11 - Abort job - ERROR (version 7.1-SNAPSHOT, build 1 from 2017-08-23 17.37.41 by olbicoserviceuser) : Aborting job.
2022/08/10 17:21:11 - DnB Data Preparation - Finished job entry [Abort job] (result=[false])
2022/08/10 17:21:11 - DnB Data Preparation - Job execution finished
2022/08/10 17:21:11 - Spoon - Job has ended.
2022/08/10 17:21:47 - Spoon - Spoon
Now though it seems to work, I wonder if there is a cleverer way to let the 'false' hop to be chosen apart from just making it crash by an unknown command. I tried return false, false, set errorlevel. But I just cannot find the proper way.
CodePudding user response:
'EXIT /B 1'
With the '1' indicating that the result of the batch file was false, so it hops to the 'red arrow' in spoon.