Refine synchronisation

In an answer to a post I made back on 18 Feb 2014, 'Synchronising files of different types', I got a script from Leo that did just this. I wonder if that script could be amended to do the following:
take a file with the name 110527_9021_2_3.jpg: is it possible to synchronise this with 110527_9021.dng AND 110527_9022.dng AND 110527_9023.dng, or, if not all of these, with at least the first one (110527_9021.dng)?

(Explanation: 110527_9021_2_3.jpg is an HDR image formed by merging the three rawfiles 110527_9021.dng, 110527_9022.dng and 110527_9023.dng. I want to select these 3 dng files as backup for this HDR image so I can reconstitute it if necessary, but I have a lot of sets of files so I would like to do it automatically if possible.)

It may be possible to write a script to do that.

More exact rules about how to find the different filenames are needed, though.

110527_902123.jpg

  • 110527_9021.jpg
  • 110527_9022.jpg
  • 110527_9023.jpg

That makes sense, but what happens when, say, the first file ends in a 9? This, or something else?

110527_90293031.jpg

  • 110527_9029.jpg
  • 110527_9030.jpg
  • 110527_9031.jpg

Are there always exactly three files?

Sorry for not replying sooner.
You're right as to what happens when the first file ends in a 9.
There are either 3, or with my latest camera, 5 files.
Hope this helps.

Hi Leo! Has this defeated you?

No, I'm just not spending my weekend personal time writing custom scripts for people. (Well, I do sometimes, but please don't expect me to.)

You get personal time??? What kind of techie gets personal time?

Leo, please let me know if you're going to do this or advise me where I can find out.

(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]

I've edited the XML and script above to improve it slightly, so if you grabbed it in the few minutes before I posted this reply, please grab the new version.

The improvement is to handle JPG files that only have one corresponding DNG image (e.g. "110527_1234.dng" will be left unselected if "110527_1234.jpg" exists. And "test.dng" if "test.jpg" exists, too.)

Hi Leo
Sorry for my previous impatience and thank you for the work you've obviously put into this.
At present, when I click on the newly created button, I'm getting the error message 'Windows cannot find 'Option'. Make sure you typed the name correctly, then try again.'
Walter

Are you using Opus 10? The button depends on scripting, which was added in Opus 11.

Time to upgrade!

I am now upgraded, and have had the opportunity to test the button - it works like a dream. Words like 'brilliant' and 'elegant' come to mind. This script accomplishes in an instant what otherwise would have taken an age. Thanks for all my saved labour for which I hope your satisfaction in crafting this gem is some recompense.