|
Answer» Not sure what I am doing wrong here... WINDOWS 7 but running it as a dos batch file
have a bunch of PDFs in a folder (c:\files\*.pdf) and I want to see which of these files are not in a log file.
in the log file the messages are (once per file): >>>log.txt Login name is [email protected] Attached binary file: MAY2019_1978727_E.pdf File saved. >>>
What I thought I would need was...
echo off for %%f in (c:\files\*.pdf) DO ( echo %%~nxf findstr /m %%~nxf log.txt if %errorlevel% NEQ 0 ( echo %%~nxf was not found XXXXXXXXX ) )
PSEUDO code... for all the PDFs in the "files" folder find the file name (no path header) in the log file log.txt If the file is not in the folder then echo the file name was not found XXXXXX
basically the log file confirms all the files that should be in the folder but looking for any PDFs that are not in the log file for some reason
I am sure it is something simple but brain stopped working after VERSION 15 and a couple of hours googling lol
thanks
You can't set + read a %...% type variable in a loop; you have to use delayed expansion and use ! instead of % around the variable name.
echo off setlocal enabledelayedexpansion for %%f in (c:\files\*.pdf) DO ( echo %%~nxf findstr /m %%~nxf log.txt if !errorlevel! NEQ 0 ( echo %%~nxf was not found XXXXXXXXX ) )
If you just want a console message saying whether or not a PDF file was found in the log, you can simplify the batch a lot, to one line in fact:
for %%f in (c:\files\*.pdf) do findstr %%~nxf log.txt >nul && (echo %%~nxf found: YES) || (echo %%~nxf found: NO XXXXXXX)
Code: [Select]FAQ.pdf found: YES faq2.pdf found: NO XXXXXXX
Many thanks... this worked great. I just created a small batch file to call the one below and piped it to another log file and then just did a search for the XXXX... interesting tidbit... was expecting 15 and found 27 (out of 5500) so it has also found another potential issue we need to look into. Thank-you for that as well!
Quote from: Salmon Trout on May 05, 2019, 10:29:46 AM You can't set + read a %...% type variable in a loop; you have to use delayed expansion and use ! instead of % around the variable name.
echo off setlocal enabledelayedexpansion for %%f in (c:\files\*.pdf) DO ( echo %%~nxf findstr /m %%~nxf log.txt if !errorlevel! NEQ 0 ( echo %%~nxf was not found XXXXXXXXX ) )
|