renaming a file with the xmp file

Advanced Renamer forum
#1 : 11/09-21 02:26
Singapore
Singapore
Posts: 3
I have been tagging some files with F-Stop from android and it creates a XMP file as a side car to the original file.

Is it possible to rename the original image/movie file with the <ExifTool:Subject> from its side car (XMP)?

How do we go about doing that?


11/09-21 02:26
#2 : 12/09-21 18:20
David Lee
David Lee
Posts: 1125
The obvious solution would appear to be "Pair renaming" however it is unpredictable which files will be treated as the source and which the pairs and in general it will rename the metadata file to match the media file.

I solve this problem using a script method.

Assume for example that you wish to rename a mixture of .avi, .mov and .jpg files and each has a corresponding .xmp file with the corresponding filename.

Add all your media files and the corresponding .xmp files to the List

Open a Script method and select Apply to: name and extension

In the Prebatch script enter the code:

var files = {};
count = app.itemCount;
for (j=0; j<count; j++) {
item = app.getItem(j);
ext = item.ext.toLowerCase();
if (ext == ".avi" || ext == ".mov" || ext == ".jpg"){
filename = item.name + ext;
files[filename] = j;
}
}

and in the main script window enter:

if (item.ext.toLowerCase() == '.xmp') {
if (newName = app.parseTags("<ExifTool:Subject>")) {
if (files[item.name +".avi"]) app.getItem(files[item.name +".avi"]).newName = newName + ".avi";
if (files[item.name +".mov"]) app.getItem(files[item.name +".mov"]).newName = newName + ".mov";
if (files[item.name +".jpg"]) app.getItem(files[item.name +".jpg"]).newName = newName + ".jpg";
return newName;
}
}


To change the media filetypes edit the if statement in the Pre batch script:
if (ext == ".avi" || ext == ".mov" || ext == ".jpg")

"||" means "OR" so just add additional || ext == "filetype" elements as appropriate

and add corresponding lines in the main script:
if (files[item.name +".file"]) app.getItem(files[item.name +".filetype"]).newName = newName + ".filetype";




12/09-21 18:20 - edited 12/09-21 22:05
#3 : 12/12-21 13:24
chho
chho
Posts: 1
Reply to #2:
Thanks! Very nice!
I now have a workaround to handle heic format and reverse geocode everything!

1) imazing heic converter
--> converts heic to jpg

2) geoesetter with jpg from 1)
--> creates xmp files

3) your script (edited for heic files)
--> rename with city




12/12-21 13:24 - edited 12/12-21 13:56