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.)
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.
(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]
<?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, "_", -1, 0)</instruction>
<instruction> If (UBound(nameParts) > 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 > nextLen) Then</instruction>
<instruction> lastEnd = Left(lastEnd, lastLen-nextLen) & 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) & "_" & lastEnd & ".dng")</instruction>
<instruction> cmd.AddFile filepath</instruction>
<instruction> Next</instruction>
<instruction> Else</instruction>
<instruction> filepath.Set(parentPath)</instruction>
<instruction> filepath.Add(file.name_stem & ".dng")</instruction>
<instruction> cmd.AddFile filepath</instruction>
<instruction> End If</instruction>
<instruction> Next</instruction>
<instruction />
<instruction> cmd.SetSourceTab(ClickData.Func.DestTab)</instruction>
<instruction> cmd.AddLine "Select FROMSCRIPT DESELECTNOMATCH"</instruction>
<instruction> cmd.AddLine "Select INVERT"</instruction>
<instruction> cmd.AddLine "Select ~(*.dng) DESELECT" ' Make sure no non-DNG files are left selected.</instruction>
<instruction> cmd.AddLine "Set SOURCE=toggle"</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
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
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.