P
P
Pavel2019-10-31 16:11:58
cmd/bat
Pavel, 2019-10-31 16:11:58

How to compare the difference in two text documents and output the difference to a new text document?

I do operations with pictures, jpg , I monitor the folder where the pictures are, add the paths and names of all files to log.txt and then I calmly process it,
but the folder with pictures often involuntarily litters and the old pictures remain by necessity,
the question is: how to add to log.txt only those pictures that weren't there before?
As I see it:
we make 2 log files, log.txt and newlog.txt
log.txt - everything that was written earlier
in newlog.txt is added everything that is in the folder at the moment, then it is compared with log.txt , all the difference is written down in result.txt
is this possible? How to do it tell me?
ps here is the contents of log.txt

spoiler
c:\Program Files\Windows Sidebar\Gadgets\PicturePuzzle.Gadget\Images\setting_back.png
c:\Program Files\Windows Sidebar\Gadgets\PicturePuzzle.Gadget\Images\shuffle_down.png
c:\Program Files\Windows Sidebar\Gadgets\PicturePuzzle.Gadget\Images\shuffle_over.png
c:\Program Files\Windows Sidebar\Gadgets\PicturePuzzle.Gadget\Images\shuffle_up.png
c:\Program Files\Windows Sidebar\Gadgets\PicturePuzzle.Gadget\Images\tile16.png
c:\Program Files\Windows Sidebar\Gadgets\PicturePuzzle.Gadget\Images\tile_bezel.png
c:\Program Files\Windows Sidebar\Gadgets\PicturePuzzle.Gadget\Images\tile_drop_shadow.png
c:\Program Files\Windows Sidebar\Gadgets\PicturePuzzle.Gadget\Images\timer_down.png
c:\Program Files\Windows Sidebar\Gadgets\PicturePuzzle.Gadget\Images\timer_over.png
c:\Program Files\Windows Sidebar\Gadgets\PicturePuzzle.Gadget\Images\timer_up.png
c:\Program Files\Windows Sidebar\Gadgets\RSSFeeds.Gadget\drag.png
c:\Program Files\Windows Sidebar\Gadgets\RSSFeeds.Gadget\icon.png
c:\Program Files\Windows Sidebar\Gadgets\RSSFeeds.Gadget\images\buttonDown_Off.png
c:\Program Files\Windows Sidebar\Gadgets\RSSFeeds.Gadget\images\buttonDown_On.png
c:\Program Files\Windows Sidebar\Gadgets\RSSFeeds.Gadget\images\buttonUp_Off.png
c:\Program Files\Windows Sidebar\Gadgets\RSSFeeds.Gadget\images\buttonUp_On.png
c:\Program Files\Windows Sidebar\Gadgets\RSSFeeds.Gadget\images\flyoutBack.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
res2001, 2019-10-31
@mrusklon

Just check if the current file is in the log, if not, add it.
Something like this:

for %%a in (c:\test\*.jpg) do (
  findstr /c:"%%~fa" log.txt || echo.%%~fa>log.txt
)

If log.txt promises to grow to a LARGE size, this can significantly reduce performance and this method is of little use. If log.txt does not grow much, then it will do.
In the case of a large number of files, another option is needed. I can suggest this: we simply transfer all new files to another directory. Those. there will be no old files in the working directory. In this case, you can not check anything - a file appeared, added to the log and transferred. At the same time, a new path to the file can be written to the log, so that the log handler would normally find the files.

S
sergey, 2019-11-01
kuzmin @sergueik

windiff (MS):

Usage:

  windiff [options] path1 [path2]

Options:

-D	Compare one directory only.
-F[flags] savefile	Save composite file to 'savefile'.  
The 'flags' may consist of one or more of I (identical), L (left), R (right), F (moved leFt), 
G (moved riGht), S (Similar left), A (similiAr right), X (exit after saving list).
(e.g. -FLF saves list of Left or moved-leFt lines).

like
get diff.txt
F flags you may need others...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question