Looping through a batch file only if the response is "everything is okay"
- by PeanutsMonkey
I have a batch file that loops through the contents of a directory and compresses the files in the directory as follows;
for %%a in (c:\data\*.*) do if "%%~xa" == "" "C:\Program Files\7-Zip\7za.exe" a -tzip -mx9 "%%a.zip" "%%a"
Seeing that I am using 7zip to compress the file, it returns the message "everything is okay" if it has successfully compressed the file and it then moves onto the next file in any.
What I would like to do is the following;
Only move to the next file if the response is "everything is okay"
If the response is anything but "everything is okay", the error is logged
Since an error has occurred, it attempts to compress the file again
Once when it has succeeded i.e. "everything is okay" it goes to the next file
Steps 3 & 4 only occur a maximum of 3 times before it gives up and moves onto the next file.
How can I achieve this?