I want to delete all the files on a given folder after the extraction is successfully completed (errorlevel 0). There are several folders and inside them are several 7z splitted files, I want to delete all the 7z files from folder 1 only if the extraction went successfully, then proceed to extract file from folder 2 and then (again) delete all the 7z files inside that folder if the extraction completed successfully, and so on.
I currently have something like this:
FOR /R E:\tmp\ %%g IN (*.7z.*) DO 7z x "%%~dpng.001" -o"%%~dpg"
if %errorlevel% EQU 0 del "%%g"
So only after the whole loop is completed it starts to perform the deletion which I don't want to be done like that. I want the deletion to be triggered on every extraction successfully done.
If I set the batch like this:
FOR /R E:\tmp\ %%g IN (*.7z.*) DO 7z x "%%~dpng.001" -o"%%~dpg" & if %errorlevel% EQU 0 del "%%g"
I got somewhat what I want because the batch starts to perform the deletion after every extraction but it also does that wrong. If I have a folder inside E:\tmp\ called "Test" and inside there are files Test.7z.001 to Test.7z.003 the batch starts to extract Test.7z.001 and then proceeds to delete only Test.7z.001, then it starts to try to extract the file Test.7z.002 and, as it fails, it proceeds to delete only the file Test.7z.002 which it shouldn't because it has failed extracting which also tells me that the - if - isn't set properly, the same happens with the file Test.7z.003.
Well, that was already visible from the cmd window as I get something like this when the batch is starting:
FOR /R E:\tmp\ %g IN (*.7z.*) DO 7z x "%~dpng.001" -o"%~dpg" & if 0 EQU 0 del "%g"
7z x "E:\tmp\Test 3\test3.7z.001" -o"E:\tmp\Test 3\" & if 0 EQU 0 del "E:\tmp\Test 3\test3.7z.001"
From which it already implied an errorlevel of 0 without waiting for the extraction to be even started so no matter what it will execute the deletion. I guess it grabs the errorlevel from the result of the execution of the batch not the 7z action. I don't know much about batch, only basics and some things that I learned by necessity, batch loops are new to me. Sorry if my English isn't good, also I didn't know how to phrase the title.