@ECHO OFF
SETLOCAL
(
FOR /f "delims=" %%a IN (q21129289.txt) DO (
ECHO %%a|FIND /i "not loaded" >NUL
IF ERRORLEVEL 1 (SET "loaded=") ELSE (SET "loaded=-NOT")
FOR /f "tokens=2,3delims=:" %%c IN ("%%a") DO (
FOR /f "delims=." %%n IN ("%%~nc") DO CALL :showresult %%n %%d
)
)
)>newfile.txt
GOTO :EOF
:showresult
ECHO %1%loaded%-LOADED; %2
GOTO :eof
This batch reads from the file q21129289.txt and creates a new file newfile.txt
Parenthesising the mainline causes the output to be redirected to the file; > creates anew, >> would append.
First, the entire line is applied to %%a. This is sent to FIND which looks for not loaded (the /i means case-insensitive)
If that string is NOT found, errorlevel is set to non-zero and therefore loaded is set to an empty string. If the string is found, errorlevel is set to 0 and loaded therefore is set to -NOT.
Taking %%a as a string, we look for the second and third tokens delimited by a colon. These are applied to %%c and %%d (the next metavariable, alphabetically) so the full-filename minus the drive goes to %%c and the entire string after the second colon to %%d
Next step is to pull the same trick on the name-part only of the filename in %%c. This neatly disposes of the path, and we want the first token given a delimiter of . of the rest. This is applied to %%n
The CALL then invokes the subroutine, providing the required first-part-of-the-name and remainder-of-the-line-after-the-original-second-colon` as parameters; eg
call :showresult CAP61 299 Rows successfully loaded.
The subroutine simply strings together the first parameter (CAP61), the contents of loaded, the string -LOADED; and the first string from the end-of-line chunk (299)
The output of course is redirected to the output file.