Incorrect EXIF Date On Rename

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

Incorrect EXIF Date On Rename

Post by aimy »

Hi.

Sample files can be obtained here - https://www.sugarsync.com/pf/D7077653_05355703_181621

I have this script assigned to my custom toolbar button:

Code: Select all

$shift = 8; // Time (in hours to shift the time)
    $previewNames = "";
    $ahkHelper = "D:\SugarSync\Programs\Settings\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");
        $whenTaken = property("WhenTaken", $item);
        if ($whenTaken == '') { continue; }
        $date = formatdate($whenTaken, "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";
        } elseif ($device == "808 PureView") {
            $fileName = RegExReplace($baseName, "(\S{10})[-](.+)", "$2");
            $pattern = "$date-$fileName¬$device.$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 
This script works well previously except for the case whereby one of the file does not have EXIF Info, the script will fail:

Code: Select all

$shift = 8; // Time (in hours to shift the time)
    $previewNames = "";
    $ahkHelper = "D:\SugarSync\Programs\Settings\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";
        } elseif ($device == "808 PureView") {
            $fileName = RegExReplace($baseName, "(\S{10})[-](.+)", "$2");
            $pattern = "$date-$fileName¬$device.$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 believe this has something to do with the if ($whenTaken == '') { continue; } placement. This is because the final rename would take the next file's date. Unfortunately, I am not sure what should be the right placement.

Thanks in advance for helping.

klownboy
Posts: 3057
Joined: 28 Feb 2012 19:27

Re: Incorrect EXIF Date On Rename

Post by klownboy »

Hi aimy, I think you'll have to lay out a set of separate actions if the photos have a "date taken" or they do not. Get rid of the line if ($whenTaken == '') { continue; } and instead have a lead-in lines within the foreach loop, one for camera has a date taken and another if statement for when the photo does not. There are a number of different ways you could structure the foreach loop and the if statements, but this is one way. I tested this on your photos and it seems to work alright.

Code: Select all

$shift = 8; // Time (in hours to shift the time)
    $previewNames = "";
    $ahkHelper = "D:\SugarSync\Programs\Settings\xyEditItemNamesWindow_Helper.exe";  //edited to use aimy's file location
    $clip = "<clipboard>"; // Store current clipboard data

    foreach($item, <get SelectedItemsPathNames |>, "|") {
        $device = property("CameraModel", $item);
        $baseName = getpathcomponent($item, "base");
        $extension = getpathcomponent($item, "ext");
        $whenTaken = property("WhenTaken", $item);
        if !($whenTaken == '') {
           $date = formatdate($whenTaken, "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";
           } elseif ($device == "808 PureView") {
             $fileName = RegExReplace($baseName, "(\S{10})[-](.+)", "$2");
             $pattern = "$date-$fileName¬$device.$extension";               
           } else {
            $pattern = "$date-$baseName¬$device.$extension";
           }
        }
        elseif ($whenTaken == '') {             //this could simply be... else {
             if ($device == "SAMSUNG PL150 / VLUU PL150 / SAMSUNG TL210 / SAMSUNG PL151") {
            $pattern = "$baseName¬SAMSUNG PL151.$extension";
           } elseif ($device == "SM-N9005") {
            $pattern = "SM-N9005.$extension";
           } elseif ($device == "808 PureView") {
             $fileName = RegExReplace($baseName, "(\S{10})[-](.+)", "$2");
             $pattern = "$fileName¬$device.$extension";               
           } else {
            $pattern = "$baseName¬$device.$extension";
           }
        }
        $previewNames = $previewNames . $pattern . "<crlf>";
    }
    $previewNames = formatlist($previewNames, "e", "<crlf>");
    copytext "$previewNames";
    run """$ahkHelper""";
    #147;
    copytext $clip; // Restore clipboard data
Good luck and let me know if the output is not what you expect.
Ken
Last edited by klownboy on 22 Sep 2015 14:03, edited 1 time in total.

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

Re: Incorrect EXIF Date On Rename

Post by aimy »

Thanks @klownboy.

Unfortunately on my PC the script failed when try to run the preview window of xyEditItemNamesWindow_Helper.exe.

XYplorer hang and close. Any fix for this?

Thank you.

klownboy
Posts: 3057
Joined: 28 Feb 2012 19:27

Re: Incorrect EXIF Date On Rename

Post by klownboy »

Hi Aimy, sorry I forgot to change the line that references the xyEditItemNamesWindow_Helper.exe file. Please change that line (line #3) to what you had which was:

Code: Select all

$ahkHelper = "D:\SugarSync\Programs\Settings\xyEditItemNamesWindow_Helper.exe";
I had to download that file and I placed it in my scripts folder, <xyscripts>. You have the file in D:\SugarSync\Programs\Settings
Let me know if you have any issues.
Ken
Edit: I updated the my post above such that it uses your xyEditItemNamesWindow_Helper.exe file location.

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

Re: Incorrect EXIF Date On Rename

Post by aimy »

Thanks klownboy.

I also forgot to tell you that I have already changed that part actually but the error still persist.

Thank you.

klownboy
Posts: 3057
Joined: 28 Feb 2012 19:27

Re: Incorrect EXIF Date On Rename

Post by klownboy »

Hi aimy, is that helper file, xyEditItemNamesWindow_Helper.exe located on your local drive/computer or is the folder "D:\SugarSync\Programs\Settings" on Sugarsync in the cloud? If it's not local, try putting the file somewhere on your local drive like in your XYplorer scripts folder and change the path in the script to match. I ask because it seems to work fine for me. You could try stepping through the script as well.

If and when it works for you, I'm not sure if the results are what you want. If the "date taken" data is not present in the EXIF information, do you want the arrangement of the new filename/extension to be the same result as if the "date taken" was present but without the date? It looks that way.

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

Re: Incorrect EXIF Date On Rename

Post by aimy »

Hi klownboy.

I'm really sorry.

It happened that it is actually due to my Avast antivirus detected that xyEditItemNamesWindow_Helper.exe as a threat and thus suspend the file access. That explains why the XYplorer hangs and closes. So I have exclude the file path now.

I'm sorry again. I have tested the script against the real case of 281 files and it works perfectly fine! Just the way I expected it.

Thanks so much to you..

klownboy
Posts: 3057
Joined: 28 Feb 2012 19:27

Re: Incorrect EXIF Date On Rename

Post by klownboy »

Thanks and no problem. I'm glad you found the cause of the problem and that it's working alright. :tup:

Post Reply