Looping through a batch file only if the response is "everything is okay"
Posted
by
PeanutsMonkey
on Super User
See other posts from Super User
or by PeanutsMonkey
Published on 2012-08-30T03:12:09Z
Indexed on
2012/08/30
3:40 UTC
Read the original article
Hit count: 430
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?
© Super User or respective owner