JSI Tip 1396. Does a restore undo all your "house cleaning"?

If you have deleted a lot of files, and find it necessary to preform a restore, all your hard work is gone. I have a solution (for the next time).

Create a folder, to be used exclusively for this function. I named mine C:\Files. Prior to performing the restore, run BeforeRS.BAT which contains:

@echo off
if exist c:\Files\*.* del /q c:\Files\*.*
date /t > c:\Files\_ZZZZZZZ
date /t > c:\Files\ZZZZZZZZ
date /t > c:\Files\BeforeRS.log
cd c:dir /b /on /s >> c:\Files\BeforeRS.log
REM If you have additional drives:
REM d:
REM cd d:REM dir /b /on /s >> c:\Files\BeforeRS.log
REM etc..
BeforeRS.BAT records every filename on your drive(s) in c:\Files\BeforeRS.log.

After the restore(s), run AfterRS.BAT which Contains:

@echo off
date /t > c:\Files\AfterRS.log
cd c:dir /b /on /s >> c:\Files\AfterRS.log
REM If you have additional drives:
REM d:
REM cd d:REM dir /b /on /s >> c:\Files\AfterRS.log
REM etc..
cd c:\Files
FC /LB9999 /1 BeforeRS.log AfterRS.log > DiffRS.tmp
if exist DiffRSBefore.log del /q DiffRSBefore.log
if exist DiffRSAfter.log del /q DiffRSAfter.log
set file=DiffRSBefore.log
for /f "Tokens=*" %%i in (DiffRS.tmp) do call :split "%%i" 
if exist DiffRS.log del /q DiffRS.log
findstr /B /L /V /G:DiffRSBefore.log DiffRSAfter.log >> DiffRS.log
start notepad.exe DiffRS.log
goto end
set line=%1
set line=%line:"=%
if /i "%line:~0,7%"

"***** B" goto before if /i "%line:~0,7%"

"***** A" goto After if /i "%line:~0,8%"

"c:\files" goto end if /i "%line:~0,5%"

"*****" goto end @echo %line% >> %file% goto end :before set file=DiffRSBefore.log goto end :after set file=DiffRSAfter.log :end
AfterRS.BAT performs the following functions:

1. Creates c:\Files\AfterRS.log with record for every filename on your drive(s).

2. Compares the BeforeRS.log with the AfterRS.log and writes DiffRS.tmp with the difference, using the FC command.

3. Separates the DiffRS.tmp into DiffRSBefore.log and DiffRSAfter.log, without the **** break images.

4. Uses the Findstr command to create DiffRS.log, containing only those files that were created by the restore.

5. Opens the DiffRS.log file in Notepad.

After inspecting DiffRS.log (and removing any folders/filenames you don't want deleted), run DiffRS.BAT, which contains:

@echo off
cd c:\Files
for /f "Tokens=*" %%i in (DiffRS.log) do call :parse "%%i"
del /q *.*
goto end
set file=%1
set File=%file: "=%
set File=%file:"=%
@echo "%file%"
del /f /q "%file%"
NOTE: The entire process takes a few minutes on my C: and D: drives (60K files).
Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.