Refine synchronisation

(Please be more patient! You asked on Friday afternoon my time and then asked for an update on Monday morning.)

The button I've made for you works like this.

[ul][li]Open the JPG folder and the DNG folder side by side.

[/li]
[li]Click on the JPG side so it is active.




[/li]
[li]Click the button.




It will select the DNG files on the other side which are not related to any of the JPG files. It will also make the DNG side active. So you can check the right files are selected (in case the script made a mistake) and then delete or move the unwanted files.

(I'd recommend moving them at first, in case the script has any errors or misunderstandings about the naming conventions etc. That way you can still get back the old files if you realise later they were needed.)[/li][/ul]

Here is the button XML:

(See How to add buttons from this forum to your toolbars if needed.)

<?xml version="1.0"?> <button backcol="none" display="both" textcol="none"> <label>Select HDR DNG</label> <icon1>#default:advancedselect</icon1> <function type="script"> <instruction>Option Explicit</instruction> <instruction>Function OnClick(ByRef ClickData)</instruction> <instruction> Dim cmd</instruction> <instruction> Dim file, filepath, parentPath</instruction> <instruction> Dim nameParts, i</instruction> <instruction> Dim lastEnd, lastLen, nextLen</instruction> <instruction /> <instruction> Set cmd = ClickData.Func.Command </instruction> <instruction> Set filepath = DOpus.FSUtil.NewPath</instruction> <instruction> Set parentPath = ClickData.Func.DestTab.Path</instruction> <instruction /> <instruction> cmd.Clear</instruction> <instruction> cmd.ClearFiles</instruction> <instruction> </instruction> <instruction> For Each file In ClickData.Func.SourceTab.Files</instruction> <instruction> nameParts = Split(file.name_stem, &quot;_&quot;, -1, 0)</instruction> <instruction> If (UBound(nameParts) &gt; 1) Then</instruction> <instruction> lastEnd = nameParts(1)</instruction> <instruction> For i = 1 To UBound(nameParts)</instruction> <instruction> lastLen = Len(lastEnd)</instruction> <instruction> nextLen = Len(nameParts(i))</instruction> <instruction> If (lastLen &gt; nextLen) Then</instruction> <instruction> lastEnd = Left(lastEnd, lastLen-nextLen) &amp; nameParts(i)</instruction> <instruction> Else</instruction> <instruction> lastEnd = nameParts(i)</instruction> <instruction> End If</instruction> <instruction> filepath.Set(parentPath)</instruction> <instruction> filepath.Add(nameParts(0) &amp; &quot;_&quot; &amp; lastEnd &amp; &quot;.dng&quot;)</instruction> <instruction> cmd.AddFile filepath</instruction> <instruction> Next</instruction> <instruction> Else</instruction> <instruction> filepath.Set(parentPath)</instruction> <instruction> filepath.Add(file.name_stem &amp; &quot;.dng&quot;)</instruction> <instruction> cmd.AddFile filepath</instruction> <instruction> End If</instruction> <instruction> Next</instruction> <instruction /> <instruction> cmd.SetSourceTab(ClickData.Func.DestTab)</instruction> <instruction> cmd.AddLine &quot;Select FROMSCRIPT DESELECTNOMATCH&quot;</instruction> <instruction> cmd.AddLine &quot;Select INVERT&quot;</instruction> <instruction> cmd.AddLine &quot;Select ~(*.dng) DESELECT&quot; &apos; Make sure no non-DNG files are left selected.</instruction> <instruction> cmd.AddLine &quot;Set SOURCE=toggle&quot;</instruction> <instruction> cmd.Run</instruction> <instruction /> <instruction>End Function</instruction> </function> </button>

Here is the script in a more readable format for the forum, just so people can refer to it to learn how to do similar things:

[code]Option Explicit
Function OnClick(ByRef ClickData)
Dim cmd
Dim file, filepath, parentPath
Dim nameParts, i
Dim lastEnd, lastLen, nextLen

Set cmd = ClickData.Func.Command	
Set filepath = DOpus.FSUtil.NewPath
Set parentPath = ClickData.Func.DestTab.Path

cmd.Clear
cmd.ClearFiles

For Each file In ClickData.Func.SourceTab.Files
	nameParts = Split(file.name_stem, "_", -1, 0)
	If (UBound(nameParts) > 1) Then
		lastEnd = nameParts(1)
		For i = 1 To UBound(nameParts)
			lastLen = Len(lastEnd)
			nextLen = Len(nameParts(i))
			If (lastLen > nextLen) Then
				lastEnd = Left(lastEnd, lastLen-nextLen) & nameParts(i)
			Else
				lastEnd = nameParts(i)
			End If
			filepath.Set(parentPath)
			filepath.Add(nameParts(0) & "_" & lastEnd & ".dng")
			cmd.AddFile filepath
		Next
	Else
		filepath.Set(parentPath)
		filepath.Add(file.name_stem & ".dng")
		cmd.AddFile filepath
	End If
Next

cmd.SetSourceTab(ClickData.Func.DestTab)
cmd.AddLine "Select FROMSCRIPT DESELECTNOMATCH"
cmd.AddLine "Select INVERT"
cmd.AddLine "Select ~(*.dng) DESELECT" ' Make sure no non-DNG files are left selected.
cmd.AddLine "Set SOURCE=toggle"
cmd.Run

End Function[/code]