This script accepts two parameters:
@ECHO OFF
:: set working names
SET "fname=%~1"
SET "dname=%~2"
:: get the text file's line count
SET cnt=0
FOR /F "usebackq" %%C IN ("%fname%") DO SET /A cnt+=1
:: split the text file, storing the last line separately from the other lines
IF EXIST "%fname%.tmp" DEL "%fname%.tmp"
(FOR /L %%L IN (1,1,%cnt%) DO (
SET /P line=
IF %%L==%cnt% (
CALL ECHO %%line%%>"%fname%.tmplast"
) ELSE (
CALL ECHO %%line%%>>"%fname%.tmp"
)
)) <"%fname%"
:: append file names to 'the other lines'
FOR %%F IN ("%dname%\*.jpg") DO ECHO %%~nF>>"%fname%.tmp"
:: concatenate the two parts under the original name
COPY /B /Y "%fname%.tmp" + "%fname%.tmplast" "%fname%"
:: remove the temporary files
DEL "%fname%.tmp*"
The get the text file's line count
part simply iterates through all the lines, while increasing the counter. You can use a different approach if you know for sure what the last line is like, or if you know that it must contain a certain substring (even if it's just one character). In that case you can replace the FOR loop used above with this FOR loop:
FOR /F "delims=[] tokens=1" %%C IN ('FIND /N "search term" ^<"%fname%"') DO SET cnt=%%C
where search term
is the term that can be matched by the last line.