Saving a difference to a text file

General questions about using ExamDiff Pro, ideas for new features, bug reports, and usage tips.
JeremyNicoll
Expert Member
Posts: 108
Joined: Sun May 02, 2010 12:00 pm
Location: Edinburgh

Re: Saving a difference to a text file

Post by JeremyNicoll »

I decided to have a go at this to see how I'd do it.

I have a folder that contains various "macro" files for my text editor, at: C:\Dropbox\JN_Kedit_Macros\

I made a new folder on my desktop, named "Kedit2", and copied everything from the first folder into it. I then added a few extra folders and extra files to this second set of folders and files. Those are the excess files I hope to find later.

I made two lists of files and folders, each list containing the full path of each file/subfolder in the original folders, one per line. The commands used were

C:\>dir "C:\Dropbox\JN_Kedit_Macros" /b /s > "C:\Users\myuserid\Desktop\Kedlist1.txt"

and

C:\>dir "C:\Users\myuserid\Desktop\Kedit2" /b /s > "C:\Users\myuserid\Desktop\Kedlist2.txt"

The first few lines of the first file - Kedlist1.txt - look like:

C:\Dropbox\JN_Kedit_Macros\aa.kex
C:\Dropbox\JN_Kedit_Macros\AdjTimes.kex
C:\Dropbox\JN_Kedit_Macros\allplus.kex
C:\Dropbox\JN_Kedit_Macros\asccodes.kex

and the second file - Kedlist2.txt -

C:\Users\myuserid\Desktop\Kedit2\aa.kex
C:\Users\myuserid\Desktop\Kedit2\AdjTimes.kex
C:\Users\myuserid\Desktop\Kedit2\allplus.kex
C:\Users\myuserid\Desktop\Kedit2\asccodes.kex

I made a copy of the first file, named Kedlist1-rvs.txt and edited/revised it using my text editor.
I changed the "C:\Dropbox\JN_Kedit_Macros" on each line to "C:\Users\myuserid\Desktop\Kedit2"
so it now looked like

C:\Users\myuserid\Desktop\Kedit2\aa.kex
C:\Users\myuserid\Desktop\Kedit2\AdjTimes.kex
C:\Users\myuserid\Desktop\Kedit2\allplus.kex
C:\Users\myuserid\Desktop\Kedit2\asccodes.kex

With my text editor that took one command. I expect global search & replace would do the same in
any editor.

That file now contained the fully-pathed names that we'd expect to find in the Desktop\Kedit2 folder,
for each of the files/subfolders that actually were in C:\Dropbox\JN_Kedit_Macros.

I used EDP to compare the two files, that is: "C:\Users\myuserid\Desktop\Kedlist1-rvs.txt"
and "C:\Users\myuserid\Desktop\Kedlist2.txt".

It displayed the two lists of file/folder names with the expected change indicators.

I clicked on the "Show only differences" filter icon. Now what EDP displayed was a completely empty
window on the lefthandside and a list of the extra files and folders on the righthandside.

I clicked on the righthand window, did Ctrl-A to select all the lines there and pasted them into
another file. That gave me a file with just the fully-pathed names of the extra files/folders.
ceo54
Junior Member
Posts: 15
Joined: Fri Mar 05, 2021 5:57 am

Re: Saving a difference to a text file

Post by ceo54 »

@JeremyNicoll

Voila!! Copy/pasting into a new file instead of creating a difference report solves both my issues. A million thanks.

One question, how can I insert line breaks between folders paths ?
JeremyNicoll
Expert Member
Posts: 108
Joined: Sun May 02, 2010 12:00 pm
Location: Edinburgh

Re: Saving a difference to a text file

Post by JeremyNicoll »

I'm glad it helped.

Regarding line breaks ... if I copy a block of (say) four result lines from EDP into either Notepad, or my usual text editor (Kedit), I end up with four lines of text, so I'm not sure what you mean.

Are you saying the block of lines appear as one long line in your editor? What editor are you using?

Or are you saying you want some of those lines - the ones that refer to folder differences rather than file differences - to be delimited somehow? I think that would be tricky because it's not obvious which lines refer to folders and which are files.

It might be that you'd need to tackle folders first, using eg dir "C:\Users\myuserid\Desktop\Kedit2" /b /s /ad > thelistfile.txt
where the /ad means list only the things which have the "Directory" attribute.

Even then, one gets results like

C:\Users\myuserid\Desktop\Kedit2\~~Samples\From RexSwain\Another new folder
C:\Users\myuserid\Desktop\Kedit2\~~Samples\From RexSwain\Another new folder\A nested new folder

(where I defined a new folder in my test Kedit2 folder's subfolder structure, and then put another new folder inside it). Obviously if you later wrote some code to delete those items in the order they are listed, you'd get errors. That might or might not matter, depending on how careful you are being.
ceo54
Junior Member
Posts: 15
Joined: Fri Mar 05, 2021 5:57 am

Re: Saving a difference to a text file

Post by ceo54 »

What I meant was having a line break (en empty line between the folder paths and their files) likes this :

Code: Select all

C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.8387_none_08e793bfa83a89b5\ (3)                        
msvcm90.dll                                                                                                                  
msvcp90.dll                                                                                                                  
msvcr90.dll 
                                                                                                                 
C:\Windows\WinSxS\amd64_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.9600.17415_none_932b3b5547500489\ (1)                 
GdiPlus.dll   
                                                                                                               
C:\Windows\WinSxS\amd64_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.9600.19913_none_932b6bfd474fcd2a\ (1)                 
GdiPlus.dll
With the copt/pasting trick, what I'm currently getting is this :

Code: Select all

C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.8387_none_08e793bfa83a89b5\ (3)                        
msvcm90.dll                                                                                                                  
msvcp90.dll                                                                                                                  
msvcr90.dll                                                                                                                  
C:\Windows\WinSxS\amd64_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.9600.17415_none_932b3b5547500489\ (1)                 
GdiPlus.dll                                                                                                                  
C:\Windows\WinSxS\amd64_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.9600.19913_none_932b6bfd474fcd2a\ (1)                 
GdiPlus.dll
see the difference in the two reports ?

Unless there's a way to insert line breaks in the EDP's show difference only window, copy/pasting ain't gonna cut it. I also tried ctrl+A, copy with line padding but to no avail.

I think Notepad++ could accomplish this but I'm unable to find anything in my Google search results.
ceo54
Junior Member
Posts: 15
Joined: Fri Mar 05, 2021 5:57 am

Re: Saving a difference to a text file

Post by ceo54 »

The most difficult aspect here is that the line break I'm trying to add is above the folder path an not below.
MSpagni
Expert Member
Posts: 537
Joined: Mon Mar 30, 2009 12:53 am
Location: Italy

Re: Saving a difference to a text file

Post by MSpagni »

The most difficult aspect here is that the line break I'm trying to add is above the folder path an not below.
The simpleat idea could be asking the editor to replace "C:\Windows\" with (CR-LF)"C:\Windows\", i.e. put the line break before the next path instead of at the (much more difficult to define) end of current block.
N.B. This is strongly editor dependent.
ceo54
Junior Member
Posts: 15
Joined: Fri Mar 05, 2021 5:57 am

Re: Saving a difference to a text file

Post by ceo54 »

MSpagni wrote: Sat Mar 27, 2021 2:23 amThe simpleat idea could be asking the editor to replace "C:\Windows\" with (CR-LF)"C:\Windows\", i.e. put the line break before the next path instead of at the (much more difficult to define) end of current block.
N.B. This is strongly editor dependent.
Thanks for the valuable input. The issue is every folder name is unique and changing them one by one defies the entire purpose as it would take hours and hours of work. The actual list is much, much longer than the one I'm posting for example purposes.

I'm trying Notepad++ advanced regex expressions but haven't been able to find anything yet. It did everything else I wanted and this is how it finally looks:

Code: Select all

cd C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.8387_none_08e793bfa83a89b5\                         
del msvcm90.dll                                                                                                                  
del msvcp90.dll                                                                                                                  
del msvcr90.dll                                                                                                                  
cd C:\Windows\WinSxS\amd64_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.9600.17415_none_932b3b5547500489\                  
del GdiPlus.dll                                                                                                                  
cd C:\Windows\WinSxS\amd64_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.9600.19913_none_932b6bfd474fcd2a\                  
del GdiPlus.dll 
This is what I initially wanted to accomplish. To be able to paste the entire list in the Command prompt and delete all the excess files and folders in one go, now I don't know if it will work without the the line breaks or not. That remains to be seen.
JeremyNicoll
Expert Member
Posts: 108
Joined: Sun May 02, 2010 12:00 pm
Location: Edinburgh

Re: Saving a difference to a text file

Post by JeremyNicoll »

> What I meant was having a line break (en empty line between the folder paths and their files)

Ah, ok.

I think you didn't read my example (of how I recreated your problem to experiment with) carefully enough. I deliberately didn't have lists of files listed per directory (ie folder paths followed by details of files within those folders) but instead the full path of every folder and file. My dir commands were eg

dir "C:\Dropbox\JN_Kedit_Macros" /b /s

and the /b is important. It means "bare" output, ie a list that doesn't get interrupted by successive names of folders and subfolders, and because of that every line produced contains a full folder path or full file path.

The way I work, when I write scripts to do things, I /ALWAYS/ use full paths for file operations. It's much less likely to do something unintended, especially if (as I do) I surround actions with checks that files/folders I expect to exist or not exist really do exist or not. There's no ambiguity or potential for an 'accident' hitting the wrong subfolder if you always work with full paths.
ceo54
Junior Member
Posts: 15
Joined: Fri Mar 05, 2021 5:57 am

Re: Saving a difference to a text file

Post by ceo54 »

Hay, I just had an idea, instead of replacing the trailing value ")" why not ad the starting value and replace with the expression "\n" in Notepad++ to insert an empty line above the folder path and it worked. Although, it replaced the cd c: so I had to replace the ":\" with another cd c:\ to get the desired results.

Now it looks perfectly as I want it to be.

Many thanks to @psguru, @JeremyNicoll and @MSpagni for taking interest in my thread and helping me out here. It wasn't possible without your help guys. Thank you from the core of my heart.

@mods: Topic can be closed now.
ceo54
Junior Member
Posts: 15
Joined: Fri Mar 05, 2021 5:57 am

Re: Saving a difference to a text file

Post by ceo54 »

JeremyNicoll wrote: Sat Mar 27, 2021 3:30 am....
It makes sense Jeremy. I think I'll leave it as it is without the line breaks so not give command prompt any excuses of unintended actions.

As for full paths, what you wrote makes a lot of sense too but with full paths, the information becomes cluster like and it becomes difficult for differentiate with the reference file list.

I used another program for making file-list, Directory Lister. Along side the folder paths, it also lists the number of files inside that folder which I thought would be important after deleting the excess files to spot if the job is done and there are no more excess files in the OS image.

I still think, if I get the folder paths correct, as displayed in the example diff file I pasted just above this post, command prompt should get it right and locate and remove the files listed in the diff files. Let's hope so.

Pardon me for not paying attention, I have issue with focus. It's a birth defect.

Thanks for the help again, Jeremy. Highly appreciated.
JeremyNicoll
Expert Member
Posts: 108
Joined: Sun May 02, 2010 12:00 pm
Location: Edinburgh

Re: Saving a difference to a text file

Post by JeremyNicoll »

ceo54 wrote: Sat Mar 27, 2021 4:08 am I still think, if I get the folder paths correct, as displayed in the example diff file I pasted just above this post, command prompt should get it right and locate and remove the files listed in the diff files. Let's hope so.
It'll certainly remove files, but I'd prefer to be absolutely certain that it removes the right ones. The potential problem in your batch file is that it seems to operate by issuing a series of cd commands followed by simple dels. Eg

cd thisthat\other
del a
del b
del c
cd and\another\one
del a
del c
del e

Now suppose for some reason that the "cd and\another\one" doesn't work - maybe the folder no longer exists or (if on a network share) is offline or something, anything. Now the del a/c/e commands will take effect on the previous folder. The "del a" and del c" commands won't matter because you already issued those ... but the "del e" will delete file e (if it exists) from the wrong folder.

It's avoiding that sort of potentially catastrophic error that makes me use full paths. I also check that every command I issue in a script actually works (or in some situations not every one, but every critical one) before continuing. It's far better that a script that's suddenly not operating on the files you hoped it would be stops and says so, than that it goes ahead and affects the wrong files.
ceo54
Junior Member
Posts: 15
Joined: Fri Mar 05, 2021 5:57 am

Re: Saving a difference to a text file

Post by ceo54 »

JeremyNicoll wrote: Sat Mar 27, 2021 5:16 amNow suppose for some reason that the "cd and\another\one" doesn't work - maybe the folder no longer exists or (if on a network share) is offline or something, anything. Now the del a/c/e commands will take effect on the previous folder. The "del a" and del c" commands won't matter because you already issued those ... but the "del e" will delete file e (if it exists) from the wrong folder.
I agree, this might happen in the situations you described but I will be creating a brand new list for the mounted image and comparing it with the reference file list I have from the previous version. Choosing to see the difference only from the toolbar will only show me the available excess files in the mounted image. Other than that, once the removing process is completed, I'll make another list from the mounted image and re-compare it with the reference file list to reassure that no files are displayed now so to confirm the excess files are removed.

The build image under go intensive testing before being deployed on real machines. Far higher chance of getting it wrong somewhere else than here.

But the point you made is important one for especially someone like me who is working with system files. I must keep that in mind. Thank you for bringing this to my attention.
Post Reply