I hope you are all keeping well and SAFE.
I have been working on something for days and days, and I am so very close to it working but I can't seem to get the last bit to work. I really have tried very hard. He is what I am attempting to do . . .
[1] If the file does NOT exist, show a message - Done and works.
[2] If the file is empty, show a message - Done and works.
[3] If the file does NOT contain TODAYS date, show a message - Does NOT work.
[4] If the file does contain TODAYS date, use a FILTER list to extract the data in the FILTER, delete DUPLICATES, show a message and output the results - Does NOT work.
I have used the TEMP folder for calculations.
It picks up TODAYS date correctly.
The CBS file is correct and shows the correct number of lines.
The FILTER file shows the correct data from the FILTER list for what is in the CBS file.
The TODAY file shows the correct extracted data if there is any from the FILTER list, but has DUPLICATES.
The DUPLICATES file shows the correct data but for ALL days, which is correct, but then I need to extract the data which is TODAYS date ONLY, and also NO DUPLICATES.
On number [3] above, the message shows when there is NO data for TODAY.
On number [4] above, if there is data for TODAY, it outputs the correct data it is asked to via the FILTER list, but includes DUPLICATES [ I just want the last entries for each if there is any ], and gives a message saying "The system cannot find the file specified." I have narrowed it down to this line . . .
Code: Select all
for /f "tokens=* delims= " %%a in (%Today%) do (
find "%%a" < %OFN% >nul || >> %OFN% echo.%%a
)
Code: Select all
@echo off
title Summary [ TODAY ] & mode con: cols=80 lines=9 & color 17
setlocal EnableDelayedExpansion
set "LOG=Corruption_Sum.log"
set "OFN=%Temp%\%LOG%"
set "CBS=%Temp%\CBS_log.txt"
set "Filter=%Temp%\Filter_File.txt"
set "Duplicates=%Temp%\Duplicates.txt"
set "Today=%Temp%\Today.txt"
for /f %%i in ('WMIC OS Get LocalDateTime /Value') do for /f %%j in ("%%i") do set "%%j"
set "Y=%LocalDateTime:~0,4%"
set "M=%LocalDateTime:~4,2%"
set "D=%LocalDateTime:~6,2%"
if exist %OFN% (del /f /q %OFN% >nul 2>&1)
if not exist "%windir%\Logs\CBS\CBS.log" (
mode con: lines=9 & color C
echo. & echo THERE IS NO FILE.
echo. & echo ^>Press ANY key to EXIT . . . & pause >nul & Exit
)
for %%a in ("%windir%\Logs\CBS\CBS.log") do ^
if %%~za LEQ 3 (
mode con: lines=9 & color C
echo. & echo THE FILE IS EMPTY.
echo. & echo ^>Press ANY key to EXIT . . . & pause >nul & Exit
)
copy "%windir%\Logs\CBS\CBS.log" "%CBS%" >nul
>"%Filter%" (
echo Summary:
echo Operation:
echo Operation result:
echo Last Successful Step:
echo Total Detected Corruption:
echo CBS Manifest Corruption:
echo CBS Metadata Corruption:
echo CSI Manifest Corruption:
echo CSI Metadata Corruption:
echo CSI Payload Corruption:
echo Total Repaired Corruption:
echo CBS Manifest Repaired:
echo CSI Manifest Repaired:
echo CSI Payload Repaired:
echo CSI Store Metadata refreshed:
echo Total Operation Time:
::echo Not all CSI corruption was fixed
echo CSI corruption was fixed
echo Count of times corruption detected:
echo Failed to run Detect and repair
::echo Reboot mark cleared
echo Reboot mark
)
type "%CBS%" | findstr /I /G:"%Filter%" >> "%Duplicates%"
for %%R in ("%Duplicates%") do ^
if %%~zR==0 (
echo. & echo NO SUMMARY [ TODAY ONLY ] WAS FOUND.
del "%Duplicates%" "%CBS%" "%Filter%"
echo. & echo ^>Press ANY key to EXIT . . . & pause >nul & Exit
) else (
del "%Duplicates%"
cls & mode con: lines=11 & color C
echo. & echo SUMMARY [ TODAY ONLY ] WAS FOUND.
type "%CBS%" | findstr /I /G:"%Filter%" >> "%Duplicates%"
type "%Duplicates%" | findstr "%Y%-%M%-%D%" >> "%Today%"
del "%CBS%" "%Filter%"
for /f "tokens=* delims= " %%a in (%Today%) do (
find "%%a" < %OFN% >nul || >> %OFN% echo.%%a
)
del "%Duplicates%" "%Today%"
echo. & echo A LOG has been created.
echo. & echo ^>Press ANY key to EXIT . . . & pause >nul & Exit
)
I basically want to get the TODAYS entries ONLY, that are contained in the FILTER list, with NO DUPLICATES.
I have several that I want to do like this, so once I can get this sorted out, I will be able to apply this to the others.
Thank you in advance.
EDIT:
I have got a little bit further.
If I change the line above to . . .
Code: Select all
if %%~zR==0 (
If I remove that entry from the CBS file so there are NO DATES for TODAY, I get the message "SUMMARY [ TODAY ONLY ] WAS FOUND. A LOG has been created.", although NO log is created which is right. It should actually say "NO SUMMARY [ TODAY ONLY ] WAS FOUND." as per the code.
I think it has got something to do with the ELSE and the BRACKETS.