Renaming grouped files

Started by stonecherub, February 10, 2019, 04:42:55 PM

Previous topic - Next topic

stonecherub

My Mavic drone is set to capture 3 images with every click. I want to rename the files so that each group has the same serial number and images within the group are labeled A or B or C. (date-mav-001A, Date-mav-001B, date-mav-001C, etc.).

Surely, somebody has written a script for this, probably several.

Alas, I used to teach programming but have not written scripts in many years and find that I have reached the age where I can't just polish my prior knowledge using W3Schools and do it myself. I knew this was coming.

Mario

If you cannot create your specific naming schema with the built-in Renamer in IMatch, writing a small app will be the way to go.

The Renamer can do a lot but adding sequential letters from the alphabet is probably not easy. Maybe setting up a global variable with the contents ABCDEFG... and then using an indexed variable to grab a number matching the sequence number of the file or something...tricky. Unfortunately I don't have the time to play with this.

Maybe another user has a base app which can be adjusted to implement your custom naming schema.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

ubacher

How are the files named as they come of the drone? How do you know the members of a group?

Jingo

If you can describe the specifics of what you are looking for and include a group of images to download, I would be happy to try and come up with a specific app for you... :-)

stonecherub

The drone assigns serial numbrs as DJI0001, DJI0002, etc., so that the first image in each group is divisible by 3. I found the IM renaming function to be confusing when I tried it several years ago and have stayed with Advanced Renamer because I know it better.

Because many cameras, not just the Mavic, take multiple images for HDR purposes, I was expecting to find a turn-key version of the app I need that someone else had written.


Mario

This feature request reminded me of a feature I had on my to-do list for Renamer for quite a while.

I have to think about this for a bit more but I think I have an idea for a smart new Renamer step type that can handle my original requirement and your rather peculiar requirement as well (appending A B or C to a file name based on the input file name numbering is a bit special).
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Jingo

My offer still stands to create an app in the meantime before Mario works his magic!  I will need 2 sets of drone stack images though to work through... zip em up and attach if you could.  Thx!

sinus

Quote from: Jingo on February 12, 2019, 02:41:36 PM
My offer still stands to create an app in the meantime before Mario works his magic!  I will need 2 sets of drone stack images though to work through... zip em up and attach if you could.  Thx!

This offer honors you and is very gentle!  :)
Best wishes from Switzerland! :-)
Markus

stonecherub

Your offer is most kind, no wonder you are regarded as a hero.

Attached find two sets of 24 images, each converted from dng to jpg and reduced to around 40 Kb.

Mario

#9
I think my new step time may just be the thing you need for this.

I've made a quick check and set the Renamer to keep the original file name but append a character from a list (A,B,C,D,E...) to each group of 3 files. This is one of the modes the new step can operate in.

In combination with the sort preset you choose for the Renamer, this creates groups of 3 from your files, renames them (as configured) and appends a sequential number or one or more characters from a list. This is how it looks for groups of 3 and only appending a character:



UPDATE: I don't think this will work for your case.

Because your requirement also needs to pick the name of the first file in each group, extract the numerical part and use that name then for all other files in the group, plus appending. This is really something special and probably better done with a purpose-built app. Way to special for a generic feature, sorry.

The closed I can get automatically is



Can't you just set your drone of the software you use to process the drone photos to use your naming convention?
Besides: Do you keep each separate HDR frame? Usually these are used to produce one combined image and then are thrown away...
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Jingo

#10
Hi all... had a few minutes tonight so thought I would bang out a quick app for you.  Attached, please find a zip file that contains the new app (it even includes a fancy drone icon!).  It is certainly a bit rough around the edges currently - I will clean it up further this week.  Wanted to at least share a working version while I had the time..... 

To install, just unzip the folder to your: C:\ProgramData\photools.com\imatch6\webroot\user folder and the app should appear in the App Manager.

Here are the details:

You should sort your files by filename to ensure the files show in sequential order in the file window

Currently, you can select as many images as you'd like - but the app will only work on the first 3 images (to be enhanced!)

Once you have selected the images you would like to rename, click the Mavic Renamer App button.  It will show the 3 selected images and the new naming convention that will result from hitting the rename button.

Hit the Rename Button and voila.. the images are renamed.  I will be enhancing the app so it works on more than 3 images and will also add in some error checking as well.



Enjoy!! - Andy.

ubacher

Just a question: Have you looked at the metadata of the files coming from the drone? Maybe it contains info identifying the 3 files in a set.
Use the exiftool listing of all metadata. (F9-E) Note that some fields may not be imported by Imatch so will not show up in the Imatch metadata.
(If there are needed field you can tell Imatch to store them though!)

If there is metadata that distinguishes each of the 3 files then the normal renamer might be all you need.

Mario

I doubt that this will help with this very specific renaming requirement.
Identifying related files via metadata (e.g. bracket shots) is not uncommon. Problem is the grouping by that data, using the name of the first file in each group as the file name for all files in the group, and appending a letter A, B, C to each file.

Solving the "group files by" and "append this" is the main goal of the new Renamer step I mentioned above.
This allows users to solve problems like "rename all files by date and if this produces identical file names, append 1 to the first file, 2 to the second file".

This was impossible to do before.
The "append unique number" step can be used to ensure unique file names, but then the first file in each 'group' does not get a number because the file name is unique. So, assuming your rename produces:

2019-02-13
2019-02-13-1
2019-02-13-2
2019-02-13-3


would be the result. The first file name gets no number because it is unique.
The new "Group By" step included in the next IMatch release handles this smarter. You can produce things like:

2019-02-13-1
2019-02-13-2
2019-02-13-3
2019-02-13-4


or

2019-02-13-A
2019-02-13-B
2019-02-13-C
2019-02-13-D


and even

zul-989-I
zul-989-II
zul-989-III
zul-989-IV


if this is what you need (using such numeric file names + appendix is not uncommon for certain user groups).

The new Renamer step can group files into fixed-size groups ("group of 3 files") and also group files by a variable, which is especially powerful. For example, if your camera records the shooting sequence of a bracket shot, you can now rename them based on that. Or, for this case, if the Drone camera records a unique id for each HDR sequence, this can be used by the Renamer to identify the group and rename add an index or something.

I have pondered the specific problem raised in this thread that was not yet solved yesterday. The tasks is to "Find groups of 3 sequential files" (we can do that now) and then "rename all files based on the name of the first file in each group" (not yet) and "append a number of character) (can do that).

Accessing the name of the first file in the group (at the stage the step is running, which means that the file name may no longer be the original file name if other steps have already modified it) and then transforming it to something useful and doing that in a generic way useful for at least a substantial part of the IMatch user base is the culprit.

Creating a special solution which produces exactly what stonecherub requests is trivial. But probably useful only for him and his drone software. This is not something many IMatch users will need. Or at least not in that format. Still, I can see some use for this for various other purposes so I will do some additional thinking how to implement a generic feature for this. I think it will be doable with additional Renamer variables which allow to access the current state of the rename operation...


-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Jingo

Reading Mario's response this morning, I realized I didn't always use the first filename as the base for the renaming... so, a quick tweak and here is an updated version that fixes that issue.  Enjoy!


Mario

While running (always a great time to think things through) I've figured out a quite neat solution for peculiar rename challenges like this (and many others).
The key was, as I had guessed, to leverage the power of IMatch variables and create some new variables for the Renamer content.

I've already added the variable {Renamer.TargetFileName} for the next release. This variable holds the 'current' target file name at the time the step using it is executed. This allows to create Renamer presets which check the file name produced so far and then act accordingly. Not often needed but when you need it can be a real time-saver.

So, the new "Group By" step has to keep track of its current state (e.g. which files it has already seen, when its time to create a new group etc.). I used this existing data for two new variables only available when a "Group By" step is running:

{Renamer.Group.Index} This is the one-based index of the current file in the current group. If you group files by 3, this variable goes 1,2,3, 1,2,3 ...
{Renamer.Group.FileNames} This variable contains the file names produced for the current group so far. It changes over time, while the "Group by" step is accumulating new files into the current group.

To get the name of the first file in the current group, we can use the neat index: variable function:{Renamer.Group.FileNames|index:first}.

To make all this usable with the new "Group by" step I've just added a generic text parameter which supports a free mix of literal text and variables. Basically the same that the "Text and Variables" step does.

All this combined in the new "Group By" step allows us to

a) group files by a fixed number or a variable expression
b) Append a sequential number to each file in the group, starting at 1
c) Append a token from a list of tokens (e.g. for custom postfixes, latin nubers, characters, ...)
d) Append an arbitrary text produced from variables, including the first or any file name in the current group.
e) Combine all that freely.

I'm quite sure that not many users will ever use this step - because most users have fairly simple file naming conventions (good!).
But sometimes you need something like this, and then it's great to have it.
It also solves the "How to append a sequential number to all duplicate file names, including the first one", which came up quite a number of times in the past.

I've implemented all this roughly and, as a test, tried to implement the naming convention the OP requested (when I understood it correctly). These are my results (only one step needed in the Renamer):

-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

stonecherub

OK, that is a lot to digest and I truly appreciate everybody's effort.

This whole episode has revealed to me the ravages of time on my brain that I can no longer ignore. I've always been a problem-solver but these days, not so much. I hope I can last to get the geology written.

Again, thank you all.


Jingo

No worries... hopefully the latest enhancements that Mario made to the rename will help your issue - though I imagine setting this up might take a bit of finagling!  Hopefully the app code helps someone down the road - even just as yet another example of what can be done with Javascript and IM/IMWS... Enjoy!

Mario

Writing an app is always fun and hopefully somebody can learn something from your app.
I have written literally tons of apps in JavaScript, Python, C++ for IMWS now and it is always a pleasure  :)

The new versatile "Group By" Renamer step is fully generic and will solve some specific renaming challenges reported in the past.
To produce the quite complicated renaming scheme discussed in this thread, all that is needed is one step (!) in the Renamer. This is how it looks:



1. Each group has 3 (consecutive) files.
2. Insert the result of the variable (see below)
3. Insert a token from the list (this allows us to get the A B C)

The variable is (arguably) tricky. This is how it looks:

{File.DateTime|format:YYYY-MM-DD}-mav-{Renamer.Group.FileNames|index:first;replace:DJI_==}

I needed 3 parts to get the desired naming schema:

Green: The prefix based on the file date and a fixed tag
Blue: Get the name of the first file in the group
Red: Remove the unwanted DJI_ part of the file name

I don't find this overly complicated.


-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook