> the pairings weren't know beforehand because some files had been
> added/removed and the rest renumbered.
The use Text Compare on the renumbered file lists.
> His request is really just another vote for a rules-based "find duplicates".
The request made no mention of duplicates.
Announcement
Collapse
No announcement yet.
Compared Numbered Files in Folders
Collapse
X
-
> Such a list could be prepared externally, but editing and preparing
> a paired file list of hunderds of files would be a potentially tedious effort...
Trying now... it took me 30s using a trivial rexexp replace.
> In my opinion, a more flexible regular expression alignment would be much
> more useful to the vast majority of users.
And much more costly to implement.
> Automation is the key.
See the above.
Leave a comment:
-
Originally posted by chrisjj View PostWhy could those name pairings not be generated externally and the list pasted in?
Leave a comment:
-
Such a list could be prepared externally, but editing and preparing a paired file list of hunderds of files would be a potentially tedious effort... not something that an average end user could be expected to be able to do.
In my opinion, a more flexible regular expression alignment would be much more useful to the vast majority of users. Automation is the key. Being able to paste in a manually prepared list might be useful to some users... but would be far less useful over all than a solution that would allow users to automate advanced file alignments programmatically.
Leave a comment:
-
> What this user wanted was a way to programatically determine and align
> files on side B based on the name of the files on side A.
The case is:
So the situation I have is the following:
FolderX\File001.jpg <-> FolderY\File005.jpg
FolderX\File002.xls <-> FolderY\File006.xls
FolderX\File003.txt <-> FolderY\File007.txt
etc.
I could match the files up manually in the folder view, but there are hundreds of files.
Leave a comment:
-
I don't believe a pasted list would necessarily have helped this user. If there were orphans or missing files on either side, it would cause an easily producable list to align the wrong files against each other.
What this user wanted was a way to programatically determine and align files on side B based on the name of the files on side A. For example, capture the numeric portion of the file name and increment it in a regular expression, then align the matching file if it exists.
Leave a comment:
-
> Unfortunately, it is not something that Beyond Compare can easily
> support. We offer a feature called "Alignment Overrides", but it can only
> match if the difference is defined
BC could easily support this and a similar requirement of mine by making "Alignment overrides" accept a pasted list. Rather as Name Filters does - very well.
Leave a comment:
-
Yes, the updated script works great.
Okay, time to break out the reference files and start studying for next time.
Thanks for all your help.
Leave a comment:
-
I provided an updated script in post #7. Didn't you try it?
We call BC3 first with the /quickcompare parameter to get a return code. Everything you need to know is in the BC3 help file under the Command line reference:
/qc=<type>, /quickcompare=<type>
Performs a quick comparison of the two files and sets the DOS ErrorLevel on exit. <type> can be size, crc, or binary, or can be left off to do a rules-based comparison. ErrorLevels are documented below.
Level - Meaning
0 - Success
1 - Binary Same
2 - Rules-Based Same
11 - Binary Difference
12 - Similar
13 - Rules-Based Difference
14 - Conflicts Detected
100 - Unknown error
101 - Conflicts Detected. Merge output not written. (Merge Sessions Only)
Leave a comment:
-
Oh... yeah... thanks! hahaha
Sorry, maybe I wasn't clear enough. Yeah, I got that #5 was just a sample, so I was trying my own little test first before putting it into the larger script. Looking at the command you're calling, I thought the objective was to open a window with the results of the comparison between LeftFile and RightFile. Am I wrong? Is that not what it's doing? My point was that I'm not getting the GUI at all, just a message box with a number in it. How do I find out the meaning of the return values? I'm not really familiar with BC's CLI, but I can see I'm going to have to start studying it.
I was also thinking that with some modifications, a similar script might also be able to help larryvega in "Compare folders disregarding file names": for each file in Folder X, compare it to EVERY file in Folder Y, and report back on whether a match was found and if so, which pairs. Granted that a rules-based comparison could be prohibitively slow depending on the amount of data, if the files are expected to be the same with only the file names having been changed, a quick comparison may be sufficient.
I've actually already resolved the specific issue I had when I posed my original question, but the problem intrigues me. In both cases (mine and larryvega's), the files are expected to be the same, but the difficulty arises because they have been renamed in a manner which may or may not be known. Now that you've given me my first introduction to scripting BC, I'm thinking that may be a workable solution for the general case where the filenames are not known ahead of time.
Leave a comment:
-
No, script 5 was not a solution on a silver platter...it was a trimmed down example of calling BC3 directly instead creating a cmd script and waiting for it to close before moving on. I figured you'd be able to take the goods out of script #5 and apply them to script #4 yourself. It would look something like this:
Code:Option Explicit Const ForReading = 1 Const ForWriting = 2 Dim WSHShell, fso, oFolder, oFile, BC3 Dim strLeftPath, strRightPath, strLeftFile, strRightFile Dim intOffset, intLeftNum, intRightNum, lngResult, s, i Set WSHShell = CreateObject("WScript.Shell") Set fso = CreateObject("Scripting.FileSystemObject") strLeftPath = "D:\LeftPath\" strRightPath = "D:\RightPath\" intOffset = 4 BC3 = """C:\Program Files\Beyond Compare 3\BComp.exe"" " If fso.FolderExists(strLeftPath) And fso.FolderExists(strRightPath) Then Call Main Set fso = Nothing MsgBox "Done" ' Iterate through files and compare Sub Main Set oFolder = fso.GetFolder(strLeftPath) For Each oFile In oFolder.Files strLeftFile = oFile.Name i = InStr(strLeftFile, ".") s = Left(strLeftFile, i - 1) intLeftNum = Val(Right(s, 3)) If intLeftNum > 0 Then intRightNum = intLeftNum + intOffset strRightFile = Left(strLeftFile, i - 4) & Right("00" & intRightNum, 3) & Mid(strLeftFile, i) If fso.FileExists(strRightPath + strRightFile) Then lngResult = WSHShell.Run(BC3 + "/quickcompare=binary " + + """" + strLeftPath + strLeftFile + """ """ + strRightPath + strRightFile + """", 0, True) if lngResult > 1 And lngResult Then WSHShell.Run BC3 + """" + strLeftPath + strLeftFile + """ """ + strRightPath + strRightFile + """" End If End If Next End Sub Function Val(strNumber) Dim i, s, intValue s = Trim(strNumber) intValue = 0 If IsNumeric(s) Then For i = 1 To Len(s) intValue = intValue + InStr("123456789", Mid(s, i, 1)) * 10 ^ (Len(s) - i) Next End If Val = intValue End Function
Leave a comment:
-
Hey, I've just tried your script in #4. Looks like it's going to be useful. Thanks!
I do have a question... It seems to be opening the comparisons one at a time, and I have to close BC to get the next one. Is there a way to get the comparisons in separate tabs instead of closing it each time? Is that what you were trying to do in #5? I can't seem to get that one to work in my test. I just get a message box that returns "11", but no BC GUI. Am I missing something? The only thing I changed was LeftSide and RightSide to point to my files:
Code:Option Explicit Dim WSHShell, BC3, LeftSide, RightSide, Result Set WSHShell = CreateObject("WScript.Shell") BC3 = """C:\Program Files\Beyond Compare 3\BComp.exe""" LeftSide = " ""I:\LeftPath\LeftFile 001.JPG""" RightSide = " ""I:\RightPath\RightFile 005.JPG""" Result = WSHShell.Run(BC3 + " /quickcompare=binary" + LeftSide + RightSide, 0, True) MsgBox Result
Leave a comment:
-
The code in the script above creates and executes a cmd file...which is a little hokey...but I was having difficulty returning the error code directly to vbScript. I'm not sure why, however, because it worked fine in my little test today:
Code:Option Explicit Dim WSHShell, BC3, LeftSide, RightSide, Result Set WSHShell = CreateObject("WScript.Shell") BC3 = """C:\Program Files\Beyond Compare 3\BComp.exe""" LeftSide = " ""D:\Test\Left.sql""" RightSide = " ""D:\Test\Right.sql""" Result = WSHShell.Run(BC3 + " /quickcompare=binary" + LeftSide + RightSide, 0, True) MsgBox Result
Leave a comment:
-
Originally posted by buraam View PostI don't think we quite solved the original poster's problem, though!
Here is one that will match your offset files and only open BC3 for ones that differ:
Code:Option Explicit Const ForReading = 1 Const ForWriting = 2 Dim WSHShell, fso, f, oFolder, oFile, BC3 Dim strLeftPath, strRightPath, strLeftFile, strRightFile, strCmdFile Dim intOffset, intLeftNum, intRightNum, lngResult, s, i Set WSHShell = CreateObject("WScript.Shell") Set fso = CreateObject("Scripting.FileSystemObject") strLeftPath = "D:\LeftPath\" strRightPath = "D:\RightPath\" intOffset = 4 BC3 = """C:\Program Files\Beyond Compare 3\BComp.com"" " strCmdFile = fso.GetAbsolutePathname(".") + "\compare.cmd" If fso.FolderExists(strLeftPath) And fso.FolderExists(strRightPath) Then Call Main Set fso = Nothing MsgBox "Done" ' Iterate through files and compare Sub Main Set oFolder = fso.GetFolder(strLeftPath) For Each oFile In oFolder.Files strLeftFile = oFile.Name i = InStr(strLeftFile, ".") s = Left(strLeftFile, i - 1) intLeftNum = Val(Right(s, 3)) If intLeftNum > 0 Then intRightNum = intLeftNum + intOffset strRightFile = Left(strLeftFile, i - 4) & Right("00" & intRightNum, 3) & Mid(strLeftFile, i) If fso.FileExists(strRightPath + strRightFile) Then Set f = fso.OpenTextFile(strCmdFile, ForWriting, True) f.writeline BC3 + "/quickcompare=binary """ + strLeftPath + strLeftFile + """ """ + strRightPath + strRightFile + """" f.writeline "if errorlevel = 2 " + BC3 + """" + strLeftPath + strLeftFile + """ """ + strRightPath + strRightFile + """" f.close Set f = Nothing WSHShell.Run """" + strCmdFile + """", 0, True fso.DeleteFile strCmdFile End If End If Next End Sub Function Val(strNumber) Dim i, s, intValue s = Trim(strNumber) intValue = 0 If IsNumeric(s) Then For i = 1 To Len(s) intValue = intValue + InStr("123456789", Mid(s, i, 1)) * 10 ^ (Len(s) - i) Next End If Val = intValue End Function
Leave a comment:
-
Hmm... I think in this case, the rules-based contents of the files may be the same, but the binaries could be different. I believe Beyond Compare is the only file-comparison tool I've come across that can handle a rules-based comparison; most of the others I've looked at can only compare the binaries.
I had another set of data previously that was the way you described (Folderx\*001.*<->FolderY\*001.*) and I was able to successfully compare them, but I was puzzled by this one because it seems some extra files have been added, thereby skewing the numbering. (Actually, come to think of it, it may actually have been the other way around, some files deleted from one folder and the remaining ones renumbered to fill in the gaps.)
Ideally I would like to find which files are in one folder and not the other. At least by knowing the difference in the numbering I can have a guess and the probable number of extras, and it's relatively small. My thought was that perhaps I could batch-rename all the files to have consistent numbering and use the results of the comparison to help me find the extras by hand, but I was just wondering whether there was an easier way.
There are a couple of things I saw in other posts that may help me:
In this case, I believe I know the area of the binary that might be different. If I could instruct the comparison to ignore that area, it might be a step in the right direction. Someone asked a question whether it was possible to specify the offset at which to start the comparison. At the time, the answer was that it's on the wishlist; has there been any progress on it since?
I also found a thread called "Compare folders disregarding file names", which sounds very close to what I'm trying to do. I don't think we quite solved the original poster's problem, though!
Leave a comment:
Leave a comment: