EXIF Conditional Rename

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
aimy
Posts: 182
Joined: 26 Feb 2007 15:44

EXIF Conditional Rename

Post by aimy »

Hi all, I have this script..

Code: Select all

if (<prop CameraModel> == "SAMSUNG PL150 / VLUU PL150 / SAMSUNG TL210 / SAMSUNG PL151") {
      //$CameraModel = "test"
      //rename b, '<dateexif yyyymmdd.hhnnss>-*¬<prop CameraModel>', p;
    rename b, '<dateexif yyyymmdd.hhnnss>-*¬SAMSUNG PL151', p;
    }
   elseif (<prop CameraModel> == "SM-N9005") {
       rename b, '<dateexif yyyymmdd.hhnnss>¬<prop CameraModel>', p;
    }
        else {
          rename b, '<dateexif yyyymmdd.hhnnss>-*¬<prop CameraModel>', p;
         }
        rename r, "\s{1,100}[.] > ."         
which intends to work like this..

Code: Select all

1. If the camera model is "SAMSUNG PL150 / VLUU PL150 / SAMSUNG TL210 / SAMSUNG PL151", then rename the image file to '<dateexif yyyymmdd.hhnnss>-*¬SAMSUNG PL151'
2. If the camera model="SM-N9005", then rename the image file to '<dateexif yyyymmdd.hhnnss>¬<prop CameraModel>'
3. For any other conditions, just rename the file to '<dateexif yyyymmdd.hhnnss>-*¬<prop CameraModel>'
But the above script seems buggy. For example, if I select multiple files with different camera model, the rename condition does not work.

If I select one file one by one, only it works.

Please help.

Thank you.

highend
Posts: 13309
Joined: 06 Feb 2011 00:33

Re: EXIF Conditional Rename

Post by highend »

You need a foreach loop and the property needs to be extracted for each file (that's the reason why using the $model variable)...

Code: Select all

    foreach($item, <get selectedItemsPathNames |>, "|") {
        $model = property("CameraModel", $item);
        $baseName = getpathcomponent($item, "base");
        if ($model == "SAMSUNG PL150 / VLUU PL150 / SAMSUNG TL210 / SAMSUNG PL151") {
            rename b, "<dateexif yyyymmdd.hhnnss>-$baseName¬SAMSUNG PL151", p, $item;
        } elseif ($model == "SM-N9005") {
            rename b, "<dateexif yyyymmdd.hhnnss>¬$model", p, $item;
        } else {
            rename b, "<dateexif yyyymmdd.hhnnss>-$baseName¬$model", p, $item;
        }
        rename r, "\s{1,100}[.] > .", , , $item;
    }
One of my scripts helped you out? Please donate via Paypal

aimy
Posts: 182
Joined: 26 Feb 2007 15:44

Re: EXIF Conditional Rename

Post by aimy »

highend wrote:You need a foreach loop and the property needs to be extracted for each file (that's the reason why using the $model variable)...

Code: Select all

    foreach($item, <get selectedItemsNames |>, "|") {
        $model = property("CameraModel", $item);
        if ($model == "SAMSUNG PL150 / VLUU PL150 / SAMSUNG TL210 / SAMSUNG PL151") {
            //$CameraModel = "test"
            //rename b, '<dateexif yyyymmdd.hhnnss>-*¬<prop CameraModel>', p;
            rename b, "<dateexif yyyymmdd.hhnnss>-*¬SAMSUNG PL151", p;
        } elseif ($model == "SM-N9005") {
            rename b, "<dateexif yyyymmdd.hhnnss>¬$model", p;
        } else {
            rename b, "<dateexif yyyymmdd.hhnnss>-*¬$model", p;
        }
        rename r, "\s{1,100}[.] > ."
    }
Thanks a lot.

But it still buggy. Various rename output was displayed for various multiple selections.

I am using XYplorer 14.10.0100

What if you try select thse 2 images from different camera and click the button which contains your script.
20140612_203742.jpg
20140612_203742.jpg (80.46 KiB) Viewed 2217 times
CAM00587.jpg
CAM00587.jpg (86.77 KiB) Viewed 2217 times
What will happen?

My output as in the screenshot.


Thank you.

<edited by highend - reason: picture resize>

highend
Posts: 13309
Joined: 06 Feb 2011 00:33

Re: EXIF Conditional Rename

Post by highend »

Try this:

Code: Select all

    foreach($item, <get selectedItemsPathNames |>, "|") {
        $model = property("CameraModel", $item);
        $baseName = getpathcomponent($item, "base");
        if ($model == "SAMSUNG PL150 / VLUU PL150 / SAMSUNG TL210 / SAMSUNG PL151") {
            rename b, "<dateexif yyyymmdd.hhnnss>-$baseName¬SAMSUNG PL151", p, $item;
        } elseif ($model == "SM-N9005") {
            rename b, "<dateexif yyyymmdd.hhnnss>¬$model", p, $item;
        } else {
            rename b, "<dateexif yyyymmdd.hhnnss>-$baseName¬$model", p, $item;
        }
        rename r, "\s{1,100}[.] > .", , , $item;
    }
Is there any reason why you don't include the file name for the SM-N9005 model (you do it for the Samsung and for everything else)?

Please remove or at least resize the pictures in your last posting to at max 800*600!
One of my scripts helped you out? Please donate via Paypal

aimy
Posts: 182
Joined: 26 Feb 2007 15:44

Re: EXIF Conditional Rename

Post by aimy »

Thanks again highend.

And sorry about the picture size. I was just intended to use the original file as much as possible.

The reason why I'm not using the filename for SM-N9005 model is because the filename from that camera is already used the datetime format, it's just that I want the date and time to be separated by a '.' rather than an '_'. That's all.

Back to your script, now it's working but it only display the preview of the new filename one by one. This is not practical since I'm going to rename 100 of files.

Thank you.

highend
Posts: 13309
Joined: 06 Feb 2011 00:33

Re: EXIF Conditional Rename

Post by highend »

Sorry but you need the foreach loop to determine the camera model for _each_ file.

It would be technically possible to create 3 batch renaming "stacks" where you could
rename all files for the _known camera models_ with a preview of the belonging files but
you can't do that for all "other" models.

So my suggestion is:
remove all "p" entries (for preview) in the

Code: Select all

rename b, ...
lines

and copy e.g. about a hundred different photos (from different cameras) into a test folder.
Select all, use the script and then look if everything went fine.

If that's the case you can use the script without the preview in the future...
One of my scripts helped you out? Please donate via Paypal

aimy
Posts: 182
Joined: 26 Feb 2007 15:44

Re: EXIF Conditional Rename

Post by aimy »

Thanks highend.

But I'm sorry to inform that the script doesn't work at all when I removed the 'p'.

The renaming process seems to take a few steps and it's wrong.

Isn't there any other way of doing this? Coz I think my objective is quite straight forward.

Let's say if I have a few predefined camera models, any way to solve this?

Thank you.

highend
Posts: 13309
Joined: 06 Feb 2011 00:33

Re: EXIF Conditional Rename

Post by highend »

And the error message / behavior that occurred when you didn't remove the "p" was?

You could do this, but it requires a slightly modified workflow but it should get what you want:

Code: Select all

    $previewNames = "";
    $selectedItems = get("SelectedItemsPathNames", "|");

    foreach($item, $selectedItems, "|") {
        $device = property("CameraModel", $item);
        $baseName = getpathcomponent($item, "base");
        $extension = getpathcomponent($item, "ext");
        if ($device == "SAMSUNG PL150 / VLUU PL150 / SAMSUNG TL210 / SAMSUNG PL151") {
            $pattern = "<dateexif yyyymmdd.hhnnss>-$baseName¬SAMSUNG PL151.$extension";
        } elseif ($device == "SM-N9005") {
            $pattern = "<dateexif yyyymmdd.hhnnss>¬SM-N9005.$extension";
        } else {
            $pattern = "<dateexif yyyymmdd.hhnnss>-$baseName¬$device.$extension";
        }
        $previewNames = $previewNames . $pattern . "<crlf>";
    }
    $previewNames = formatlist($previewNames, "e", "<crlf>");
    text $previewNames;
    #147;
Follow this guide:
1. Select all your pictures that you want to be renamed
2. Execute the script
3. From the window that pops up click on "Copy" and afterwards on "Close"
4. In the next window that you get press "CTRL + A" (to select everything)
and "CTRL + V" (to paste everything back from the previous window)
5. Click "OK"

=> You'd get a real preview window for all files for all camera models...
One of my scripts helped you out? Please donate via Paypal

aimy
Posts: 182
Joined: 26 Feb 2007 15:44

Re: EXIF Conditional Rename

Post by aimy »

highend wrote:And the error message / behavior that occurred when you didn't remove the "p" was?

You could do this, but it requires a slightly modified workflow but it should get what you want:

Code: Select all

    $previewNames = "";
    $selectedItems = get("SelectedItemsPathNames", "|");

    foreach($item, $selectedItems, "|") {
        $device = property("CameraModel", $item);
        $baseName = getpathcomponent($item, "base");
        $extension = getpathcomponent($item, "ext");
        if ($device == "SAMSUNG PL150 / VLUU PL150 / SAMSUNG TL210 / SAMSUNG PL151") {
            $pattern = "<dateexif yyyymmdd.hhnnss>-$baseName¬SAMSUNG PL151.$extension";
        } elseif ($device == "SM-N9005") {
            $pattern = "<dateexif yyyymmdd.hhnnss>¬SM-N9005.$extension";
        } else {
            $pattern = "<dateexif yyyymmdd.hhnnss>-$baseName¬$device.$extension";
        }
        $previewNames = $previewNames . $pattern . "<crlf>";
    }
    $previewNames = formatlist($previewNames, "e", "<crlf>");
    text $previewNames;
    #147;
Follow this guide:
1. Select all your pictures that you want to be renamed
2. Execute the script
3. From the window that pops up click on "Copy" and afterwards on "Close"
4. In the next window that you get press "CTRL + A" (to select everything)
and "CTRL + V" (to paste everything back from the previous window)
5. Click "OK"

=> You'd get a real preview window for all files for all camera models...
Thanks a lot again.

I've tried it. Sad to say, but it still doesn't work.

After I select all files, click on the script button, no dateexif is captured, it treated the dateexif as null.

If I select the 1st file only, click the script, it can read the dateexif, but I press Cancel.

So now I select the 1st file and the rest, click the script, but only the 1st file dateexif is captured, thus all files will have the same name in case for camera model "SM-N9005".

I'm sorry, but that's what happen.

Thank you.
Last edited by aimy on 16 Jun 2014 14:53, edited 1 time in total.

highend
Posts: 13309
Joined: 06 Feb 2011 00:33

Re: EXIF Conditional Rename

Post by highend »

One last try...

Code: Select all

    $shift = 0; // Time (in hours to shift the time)
    $previewNames = "";
    $selectedItems = get("SelectedItemsPathNames", "|");

    foreach($item, $selectedItems, "|") {
        $device = property("CameraModel", $item);
        $baseName = getpathcomponent($item, "base");
        $extension = getpathcomponent($item, "ext");
        $date = formatdate(property("WhenTaken", $item), "yyyymmdd.hhnnss", "h", $shift);
        if ($device == "SAMSUNG PL150 / VLUU PL150 / SAMSUNG TL210 / SAMSUNG PL151") {
            $pattern = "$date-$baseName¬SAMSUNG PL151.$extension";
        } elseif ($device == "SM-N9005") {
            $pattern = "$date¬SM-N9005.$extension";
        } else {
            $pattern = "$date-$baseName¬$device.$extension";
        }
        $previewNames = $previewNames . $pattern . "<crlf>";
    }
    $previewNames = formatlist($previewNames, "e", "<crlf>");
    text $previewNames;
    #147;
Before you use it, do the following:
1. Select one image file
2. In the address bar type:
text "<dateexif>";
Hit "enter"
Note that date
3. Type:
text property("WhenTaken", "<curitem>");
Hit "enter"
Note that date
4. Compare both dates
Do they differ?
If yes (and by hour)

Edit the first variable in the script.
E.g. text property("WhenTaken", "<curitem>"); delivers a time that is two hours earlier than the other command
$shift = -2;

Don't ask me why <exifdate> and "WhenTaken" differ, both are reading the exif date...
One of my scripts helped you out? Please donate via Paypal

aimy
Posts: 182
Joined: 26 Feb 2007 15:44

Re: EXIF Conditional Rename

Post by aimy »

Wow, you replied so fast.

I just edited my post to explain what is the real thing happening.

Sorry because I just notice it.

TQ.

highend
Posts: 13309
Joined: 06 Feb 2011 00:33

Re: EXIF Conditional Rename

Post by highend »

I just edited my post to explain what is the real thing happening.
I already fixed what you described in the last posted script.
One of my scripts helped you out? Please donate via Paypal

aimy
Posts: 182
Joined: 26 Feb 2007 15:44

Re: EXIF Conditional Rename

Post by aimy »

highend wrote:One last try...

Code: Select all

    $shift = 0; // Time (in hours to shift the time)
    $previewNames = "";
    $selectedItems = get("SelectedItemsPathNames", "|");

    foreach($item, $selectedItems, "|") {
        $device = property("CameraModel", $item);
        $baseName = getpathcomponent($item, "base");
        $extension = getpathcomponent($item, "ext");
        $date = formatdate(property("WhenTaken", $item), "yyyymmdd.hhnnss", "h", $shift);
        if ($device == "SAMSUNG PL150 / VLUU PL150 / SAMSUNG TL210 / SAMSUNG PL151") {
            $pattern = "$date-$baseName¬SAMSUNG PL151.$extension";
        } elseif ($device == "SM-N9005") {
            $pattern = "$date¬SM-N9005.$extension";
        } else {
            $pattern = "$date-$baseName¬$device.$extension";
        }
        $previewNames = $previewNames . $pattern . "<crlf>";
    }
    $previewNames = formatlist($previewNames, "e", "<crlf>");
    text $previewNames;
    #147;
Before you use it, do the following:
1. Select one image file
2. In the address bar type:
text "<dateexif>";
Hit "enter"
Note that date
3. Type:
text property("WhenTaken", "<curitem>");
Hit "enter"
Note that date
4. Compare both dates
Do they differ?
If yes (and by hour)

Edit the first variable in the script.
E.g. text property("WhenTaken", "<curitem>"); delivers a time that is two hours earlier than the other command
$shift = -2;

Don't ask me why <exifdate> and "WhenTaken" differ, both are reading the exif date...
Thanks a lot for your assistance.

So far, it works fine as expected! Thank you.. thank you.. I have to use 8 as the shift parameter.

Just one more question, can't the first two manual process be automated as well?

Thanks a lot.

highend
Posts: 13309
Joined: 06 Feb 2011 00:33

Re: EXIF Conditional Rename

Post by highend »

Yes, they can be automated but only (afaik) with an external utility.

Don't forget to edit the $shift variable.

Code: Select all

    $shift = 2; // Time (in hours to shift the time)
    $previewNames = "";
    $ahkHelper = self("path") . "\xyEditItemNamesWindow_Helper.exe";

    $clip = "<clipboard>"; // Store current clipboard data

    foreach($item, <get SelectedItemsPathNames |>, "|") {
        $device = property("CameraModel", $item);
        $baseName = getpathcomponent($item, "base");
        $extension = getpathcomponent($item, "ext");
        $date = formatdate(property("WhenTaken", $item), "yyyymmdd.hhnnss", "h", $shift);
        if ($device == "SAMSUNG PL150 / VLUU PL150 / SAMSUNG TL210 / SAMSUNG PL151") {
            $pattern = "$date-$baseName¬SAMSUNG PL151.$extension";
        } elseif ($device == "SM-N9005") {
            $pattern = "$date¬SM-N9005.$extension";
        } else {
            $pattern = "$date-$baseName¬$device.$extension";
        }
        $previewNames = $previewNames . $pattern . "<crlf>";
    }
    $previewNames = formatlist($previewNames, "e", "<crlf>");
    copytext "$previewNames";
    run """$ahkHelper""";
    #147;
    copytext $clip; // Restore clipboard data
I've attached a .zip file containing a compiled .ahk script which will copy the contents of the clipboard into the necessary window and clicks on the OK button.

I've tested it with 200 pictures and it worked fine.

Extract the .zip file and copy the file "xyEditItemNamesWindow_Helper.exe" into the same path where the script resides!
xyEditItemNamesWindow_Helper.zip
(407.68 KiB) Downloaded 102 times
One of my scripts helped you out? Please donate via Paypal

aimy
Posts: 182
Joined: 26 Feb 2007 15:44

Re: EXIF Conditional Rename

Post by aimy »

Thanks a lot highend.

But how do I put the file whereby the script text configured inside a button?

Sorry, but I just couldn't figure it out.

Thank you.

Post Reply