I have managed to write the following which WORKS if there is ONLY one set of entries [ as per the %Filter% ] in the thousands of lines that appear in the CBS log. If there are more than one entry for each it outputs all of them!
Is there any way that I can just get the LAST set of entries in the CBS log please?
Code: Select all
@echo off
setlocal EnableDelayedExpansion
for /f "usebackq tokens=3 " %%X in (`Reg Query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Desktop`) do set DesktopFolderRaw=%%X
for /f "usebackq delims=" %%Y in (`echo %DesktopFolderRaw%`) do (set DesktopFolder=%%Y)
set "CBS_log=%DesktopFolder%\CBS_log.txt"
set "Filter=%DesktopFolder%\Filter_File.txt"
set "Duplicates=%DesktopFolder%\Duplicates.txt"
set "Output_File=%DesktopFolder%\CBS_Candidates_Sum_TODAY.txt"
if exist "%Output_File%" (del /f /q "%Output_File%" >nul 2>&1)
copy "%windir%\Logs\CBS\CBS.log" "%CBS_log%" >nul
>"%Filter%" (
echo Summary:
echo The following actions will be performed:
echo Regeneration Candidates:
echo Removal Candidates:
echo Superseded^/LDR ^(Delta Compression^) Candidates:
echo Null-Delta Compression Candidates:
echo Mutable file Candidates:
echo Boot-Recovery Candidates:
echo Backup regeneration candidates:
echo Deletion Candidates ^(Non Driver^):
echo Driver Deletion Candidates:
echo WinSxS Orphaned Objects Candidates:
echo Manifests Orphaned Objects Candidates:
)
type "%CBS_log%" | findstr /I /G:"%Filter%" >> "%Duplicates%"
for %%R in ("%Duplicates%") do ^
if %%~zR equ 0 (
echo NOTHING FOUND.
del "%Duplicates%" "%CBS_log%" "%Filter%"
pause
goto :Exit
) else (
cls
echo FOUND.
echo Creating on the Desktop . . .
type "%CBS_log%" | findstr /I /G:"%Filter%" >> "%Duplicates%"
echo> "%Output_File%" FOUND.
for /f "tokens=* delims= " %%a in (%Duplicates%) do (
find "%%a" < "%Output_File%" >nul || >> "%Output_File%" echo.%%a
)
del "%CBS_log%" "%Filter%" "%Duplicates%"
pause
goto :Exit
)
:Exit
Thanks in advance.